Andrei
Andrei

Reputation: 3588

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.

From the php-fig site. Long story short, while not mandatory, it covers more code cases than PSR-2.

I'd like to use it in PhpStorm. Unfortunately, by default, storm doesn't offer this option. At predefined styles you have a fairly comprehensive list, but not comprehensive enough.

enter image description here

Of course, I can always define the style myself doing it by hand, but that doesn't strike me as a good idea. Mostly because I WILL miss something and if there are any updates to the PSR I can't easily update it. Not to mention I can't share it properly with my team. Except maybe exporting my .idea folder.

I googled around for a plugin or something of that sort but came up empty handed.

Upvotes: 20

Views: 29064

Answers (3)

Amitesh Bharti
Amitesh Bharti

Reputation: 15693

PHPStorm Steps for setting coding style to PSR

Navgate to Preferences>Editor>Code Style>PHP

Click on "Set From" link and select PSR12.

Click ok to save the chages

enter image description here

Upvotes: 24

Sarel
Sarel

Reputation: 1240

You can now add it from the dropdown, must've changed some time in the past 2 years. enter image description here

Upvotes: 3

LazyOne
LazyOne

Reputation: 165088

You cannot add custom entry there as a user unless you write a plugin that will do that.

WI-48160 / WI-45330 -- watch these tickets (star/vote/comment) to get notified on any progress.

The implementation of these tickets will bring a new entry in that list.


UPDATE 2019-10-08: PSR-12 Code Style preset has been added for 2019.3 version (currently in EAP stage).

Upvotes: 18

Related Questions