Skip to content

Latest commit

 

History

History
executable file
·
70 lines (41 loc) · 1.81 KB

codesniffer.md

File metadata and controls

executable file
·
70 lines (41 loc) · 1.81 KB

Setting up Codesniffer

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/

1. Install code sniffer

brew install php-code-sniffer

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

3. Unpack Coder module. I place it in ~/.drupal-coder

tar -xzf coder-8.x-2.8.tar.gz
mv coder .drupal-coder
rm coder-8.x-2.8.tar.gz

4. Create symlink to Drupals code standards.

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.

Configure PhpStorm

  1. Tell PhpStorm where to find Code Sniffer

  2. Go to Preferences -> PHP -> Code Sniffer

  3. Paste this into PHP Code Sniffer (phpcs) path: /usr/local/bin/phpcs

  4. Validate and apply

  5. Enable Code Sniffer inspection

  6. Go to Preferences -> Inspections -> PHP -> PHP Code Sniffer validation

  7. Enable this

  8. Refresh coding standards, Drupal should pop up

  9. Apply and OK

You should be ready to go. Open a Drupal module and make a coding style error to be sure.