PhpStorm enforcing PSR-2 on a subset of files

2.4k views Asked by At

I want my IDE (PhpStorm) to enforce PSR-2 compatible formatting on all of own files. Occasionally however, I have to submit patches on legacy code where I only want to commit functional changes, not changes in code style.

How can I enforce PSR-2 using PhpStorm on only a subset of files, preferably using a magic comment / marker in the files which should be enforced?

2

There are 2 answers

2
Moshe Harush On BEST ANSWER

You can set up in project settings the code style you want to apply. Step-By-Step to setup the code styling

After this you just need to press right-click the directory in project view and from the context menu select Reformat Code (Ctrl+Alt+L).

Check the setting on the dialog was open and hit "run" button.

I hope I was helpful to you.

More information on: https://www.jetbrains.com/help/phpstorm/2017.1/reformatting-source-code.html#d425724e29

1
Shajibur Rahman On

In PHPstorm you can set default code style for all specific language, Since you mentioning about php, you can follow the step to set PSR-2

  • Go to setting ( File->Setting )
  • The windows will pop up, where you can search "code style"
  • Now click on PHP and you will see "Set from" , ( Here you can set from for default code style )

PHP-STORM PSR-2 SETUP BY DEFAULT