Skip to content

Instantly share code, notes, and snippets.

@vaklinzi
Forked from nienkedekker/phpstorm-cs-fixer.md
Created November 8, 2019 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vaklinzi/213182c5622a26834e1833ce89251dfe to your computer and use it in GitHub Desktop.
Save vaklinzi/213182c5622a26834e1833ce89251dfe to your computer and use it in GitHub Desktop.
Set up PHP-CS-Fixer in PHPStorm

Use PHP-CS-Fixer in PHPStorm

  • Install PHP-CS-Fixer on your local machine according to these instructions: https://github.com/FriendsOfPHP/PHP-CS-Fixer
  • Open PHPStorm, Preferences > Tools > External Tools and enter these values: img
  • Program, edit to match your path where PHP-CS-Fixer lives: /.composer/vendor/friendsofphp/php-cs-fixer/php-cs-fixer
  • Parameters: --rules=@PSR2 --verbose fix $FileDir$/$FileName$. Note that previous verions of PHP-CS-Fixer used --levels instead of --rules.
  • Working directory: $ProjectFileDir$

Click OK and Apply. Now we'll set up a shortcut.

  • Go to Preferences > Keymap and search for "PHP Fixer" (or whatever name you gave it). Add whatever shortcut you like, I'm using ctrl + cmd + ]: img

You should be ready to go. Open a file that's not up to standards and run your shortcut, and it should be fixed once you Save the file. It will only run on Save, otherwise every keystroke will be checked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment