TODO: Maybe say something about scrutinizer and that it also checks the coding style.
This guide will explain the steps needed to setup Code Sniffer with Drupal coding standards and PhpStorm.
IMPORTANT! You need brew to perform this task, http://brew.sh/
brew install php-code-sniffer
2. Download Drupal Coder Module
Make sure you are in your home dir
cd
wget https://ftp.drupal.org/files/projects/coder-8.x-2.8.tar.gz
If you don't have wget install it using brew install wget
tar -xzf coder-8.x-2.8.tar.gz
mv coder .drupal-coder
rm coder-8.x-2.8.tar.gz
Brew installs Code Sniffer into /usr/local/Cellar/php-code-sniffer/[VERSION]/ We want a symlink pointing at Drupals code standards in /usr/local/Cellar/php-code-sniffer/[VERSION]/CodeSniffer/Standards/ for example
ln -s ~/.drupal-coder/coder_sniffer/Drupal /usr/local/Cellar/php-code-sniffer/2.6.2/CodeSniffer/Standards/Drupal
Important Make sure you change .drupal-coder in the above if you did not install coder in the suggested folder.
-
Tell PhpStorm where to find Code Sniffer
-
Go to Preferences -> PHP -> Code Sniffer
-
Paste this into PHP Code Sniffer (phpcs) path: /usr/local/bin/phpcs
-
Validate and apply
-
Enable Code Sniffer inspection
-
Go to Preferences -> Inspections -> PHP -> PHP Code Sniffer validation
-
Enable this
-
Refresh coding standards, Drupal should pop up
-
Apply and OK
You should be ready to go. Open a Drupal module and make a coding style error to be sure.