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/
- Install code sniffer
brew install php-code-sniffer
- Download Drupal Coder Module
Make sure you are in your home dir
cd
wget http://ftp.drupal.org/files/projects/coder-7.x-2.1.tar.gz
If you don't have wget install it using brew install wget
- Unpack Coder module. I place it in ~/.drupal-coder
tar -xzf coder-7.x-2.1.tar.gz
mv coder .drupal-coder
rm coder-7.x-2.1.tar.gz
- Create symlink to Drupals code standards.
Brew installs Code Sniffer into /usr/local/Cellar/php-code-sniffer/1.5.2/ We want a symlink pointing at Drupals code standards in /usr/local/Cellar/php-code-sniffer/1.5.2/CodeSniffer/Standards/
ln -s ~/.drupal-coder/coder_sniffer/Drupal /usr/local/Cellar/php-code-sniffer/1.5.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.