Drupal, PhpStorm, and PHPCS quick-start

Pre-requisites

  • Composer
  • PhpStorm

Let’s go!

1. Composer + Settings

Run the following in your terminal:

  • composer global require squizlabs/php_codesniffer:2.9.1
  • composer global require drupal/coder
  • phpcs –config-set installed_pathsΒ ~/.composer/vendor/drupal/coder/coder_sniffer

2. Configure PhpStorm

Open PhpStorm preferences (⌘,) and go to the Code Sniffer settings. Click the “…” button.Enter the path to your “phpcs” file and click “Validate”. It should be ~/.composer/vendor/squizlabs/php_codesniffer/scripts/phpcsΒ (replace “~” with your actual home directory)Β Go back to the PhpStorm preferences, navigate to “Editor Β» Inspections”, enable “PHP Code Sniffer validation”, then choose “Drupal” in the “Coding standard” dropdown.Β Enjoy!