Skip to content

Instantly share code, notes, and snippets.

@rpayanm
Last active September 11, 2020 01:26
Show Gist options
  • Save rpayanm/f64f5e23f896f590885fdb42688bb30f to your computer and use it in GitHub Desktop.
Save rpayanm/f64f5e23f896f590885fdb42688bb30f to your computer and use it in GitHub Desktop.
  1. Code style phpstorm

See https://blog.acromedia.com/making-drupal-code-standards-work-for-you-with-phpstorm-phpcs-phpcbf

Deprecated:

  1. 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: phpstorm code sniffer

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" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment