Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Latest commit

 

History

History
66 lines (40 loc) · 1.66 KB

codesniffer.md

File metadata and controls

66 lines (40 loc) · 1.66 KB

Setting up Codesniffer

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
  1. 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

  1. 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
  1. 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.

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.