PHPStorm – phpcbf as a file watcher

Install PHPCS locally via composer

composer req --dev squizlabs/php_codesniffer

For annotated config (phpcs.xml at root directory)

Configure PHPStorm

  1. Go to Preferences
  2. Tools -> File Watchers
  3. Click + -> <custom>
  4. Name: PHPCBF
  5. File type: PHP
  6. Scope: Project Files
  7. Program: $ProjectFileDir$/vendor/bin/phpcbf
  8. Arguments: $FilePath$
  9. Uncheck Auto-save edited files to trigger the watcher
  10. Uncheck Trigger the watcher on external changes