Posted on: 23rd May 2019

As a developer I like my code to meet coding standards as it makes life easier for everyone. Whenever setting up a codesniffer it can take ages to configure you have to download all the files sometimes it doesn’t work correctly, then rolling it out to others is a real hassle.


Image for post

Introducing grumphp

My great friend Pol Dellaiera ( introudced me to grumphp ( and a plugin he has created specifically for Drupal coding standards ( that works with it.

Getting grumphp

As it works directly with composer all you need to execute is

composer global require phpro/grumphp composer global update phpro/grumphp

This will allow grumphp to run on your local environment or even a staging server. Then if you are using zshrc simply add:

This will install the grumphp executable in the ~/.composer/vendor/bin folder. Make sure to add this folder to your system $PATH variable:

# .zshrc or .bashrc export PATH="$HOME/.composer/vendor/bin:$PATH"

Thats it and grumphp is running, it will now sniff your commits and any thing it doesn’t like it WILL tell you in big red text. But hopefully you’ll never find that out.

Drupal conventions

Now to add Drupal coding standards to the mix. As it uses composer you need to execute:

composer require drupol/drupal-conventions --dev

Now if you already are using grumphp like we are then look for grumphp.yml.dist or grumphp.yml

Add this to the top of your yml file

Drupal 8

imports: - { resource: vendor/drupol/drupal-conventions/config/drupal8/grumphp.yml }

Drupal 7

imports: - { resource: vendor/drupol/drupal-conventions/config/drupal7/grumphp.yml }

Now everytime you run a commit grum will tell you and pass / fail you.

If you already have code and you want to check it then by running:

./vendor/bin/grumphp run -v

Will execute everything and run it through:

Image for post

I will be adding more hints and tips to this post as time goes by.