- 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:
- 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 + ]
: