Installing and using Drupal PHP Code Sniffer on Phpstorm

Saptashwa Mandal
3 min readDec 23, 2019

--

This is a very detailed blog on installing PHP Code Sniffer and then using it in the editor and also using the coding standard Drupal

Pre-requisites:

  1. Composer
  2. PHP
  3. Phpcs (However, in the video I have shown how to install Phpcs)
  4. A working computer of course

Ok now that you meet all the pre-requisites lets start.

Adding Code Sniffer to our composer.json file

We need to include a dependency for our composer.json file in our project (Check the aforementioned video on how to create the composer file)

{
“require-dev”: {
“squizlabs/php_codesniffer”: “3.*”
}
}

(Check the indentation)

2. Installing the dependency on PhpStorm

Just click on install in the top right corner of the composer.json file

3. Installing Drupal Coder

We have to make our coding standard as Drupal and since Drupal is not there as a default coding standard we are going to have to manually download and install it.

From the link provided above (embedded in “Drupal”) we have to download coder.

After installing coder you have to unzip it which will create a file called coder.

4. Specifying Path

Open up the settings in Phpstorm and direct to Languages and Framework>PHP>Quality Tools>Php Code Sniffer. Then in configuration click on the icon showing three dots and (If the path is not already specified) Navigate to: your-project’s-root-folder/vendor/bin/phpcs.bat

Then click on “apply” and “ok”.

5. Enable Code Sniffer and Drupal as the coding standard

Open up settings again and then navigate to Editor > Inspections > PHP > Quality Tools > PHP Code Sniffer Validation. Tick the box and then click on “apply”. After clicking on “apply”, tick the “installed standard path” and direct to your project location.

After that click on the coding standard option and choose “custom”. Now direct to coder>coder_sniffer>Drupal>ruleset.xml

6. Boom. YOU ARE DONE

Now create a new .php file and try out the phpcs on your PhpStorm.

--

--

Saptashwa Mandal

Coding enthusiast and a contender in numerous competitions.