See https://blog.acromedia.com/making-drupal-code-standards-work-for-you-with-phpstorm-phpcs-phpcbf
- PHP Code Sniffer:
- Install Coder
composer global require drupal/coder
- To make the phpcs and phpcbf commands available globally, add those to your
$PATH
variable in~/.profile
,~/.bash_profile
,~/.bashrc
or~/.zshrc
:
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
- Composer Installer Plugin
composer global require dealerdirect/phpcodesniffer-composer-installer
- 3 rules in 1:
composer global require dealerdirect/phpcodesniffer-composer-installer
- Manually Set Installed Paths
To manually register the Drupal and DrupalPractice Standard with PHPCS, you must set the installed paths:
phpcs --config-set installed_paths ~/.config/composer/vendor/drupal/coder/coder_sniffer
Above, the command should return Config value "installed_paths" updated successfully
on console.
- IDE and Editor Configuration Add the symbolic path to support Drupal and DrupalPractice Standard:
ln -s ~/.config/composer/vendor/drupal/coder/coder_sniffer/Drupal ~/.config/composer/vendor/squizlabs/php_codesniffer/src/Standards/Drupal
ln -s ~/.config/composer/vendor/drupal/coder/coder_sniffer/DrupalPractice ~/.config/composer/vendor/squizlabs/php_codesniffer/src/Standards/DrupalPractice
-
Go to Language & Framework > PHP > Quality Tools, set config PHPCodeSniffer to use this path: /home/rpayanm/.config/composer/vendor/squizlabs/php_codesniffer/bin/phpcs
-
Go to File > Settings > Editor > Inspections, in right side go to PHP/Quality tools/PHP Code Sniffer validation:
You can only set one standard at a time through the UI if you need both then edit the Project_Default.xml
file in the .idea folder (.idea/inspectionProfiles/Project_Default.xml
) of your project. Find the CODING_STANDARD
option and change it to:
<option name="CODING_STANDARD" value="Drupal,DrupalPractice" />