PhpStorm 和 PSR-12,如何将其添加为默认编码风格?

PhpStorm and PSR-12, how can I add it as default coding style?

PSR-12 is an extension of PSR-2, and therefore also an extension of PSR-1. The basis of PSR-12 is PSR-2 and therefore a list of differences is provided below to assist with migration but it should be considered as an independent specification.

来自 php-无花果网站。长话短说,虽然不是强制性的,但它涵盖了比 PSR-2 更多的代码案例。

我想在 PhpStorm 中使用它。不幸的是,默认情况下,storm 不提供此选项。 在预定义样式中,您有一个相当全面的列表,但还不够全面。

当然,我总是可以自己手动定义样式,但这并不是一个好主意。主要是因为我会错过一些东西,如果 PSR 有任何更新,我不能轻易更新它。更不用说我无法与我的团队正确分享它。除了导出我的 .idea 文件夹。

我在谷歌上搜索了一个插件或类似的东西,但一无所获。

您不能以用户身份添加自定义条目,除非您编写一个插件来执行此操作。

WI-48160 / WI-45330 -- 观看这些票证 (star/vote/comment) 以获得有关任何进展的通知。

这些工单的实施将在该列表中带来一个新条目。


更新 2019-10-08: PSR-12 代码样式预设已添加到 2019.3 版本(目前处于 EAP 阶段)。

您现在可以从下拉列表中添加它,在过去 2 年中一定有过更改。

PHPStorm 将编码风格设置为 PSR 的步骤

Navgate to Preferences>Editor>Code Style>PHP

单击“设置自”link 和 select PSR12。

点击确定保存更改