HOW-TO check your code before committing it so you look like the pro you are

Jun 26, 2016

One of the best practices for high-performance web teams is to ensure quality by doing peer code reviews. You may already be aware of the Coder module, but have you tried the Coder Tough Love module and Drupal Code Sniffer project?

The Coder module includes two developer modules that assist with code review and code upgrade: Coder Review and Coder Upgrade. Each of the modules supports a plug-in extensible hook system so contributed modules can define additional review standards and upgrade routines.

Coder Review utilizes regular expressions to review source code files for code that 1) needs to change due to Drupal API changes and 2) does not satisfy Drupal coding standards. Beginning with the 5.x-2.x version, this module adds a new UI, core support, theme support, and a cache for faster display of unchanged files. It also supports rule #severity levels of "minor", "normal", and "critical."

If you want to go the extra mile, try the Coder Tough Love module which is a companion to the existing Coder module by Doug Green. Unlike Coder, which strives to follow the documented style guidelines of Drupal core, Coder Tough Love takes the tougher tactic of applying finely aged and obsessively anal wisdom from years of Drupal development and persnickety quality control.

Now if you're really hard core and want to rock Drupal like a champ, there's the Drupal Code Sniffer project provides a coding standard for PHP_CodeSniffer, based on the Drupal Coding Standards. Drupal Code Sniffer is not a Drupal module, it does not require Drupal to run and it is independent of Drupal core versions.

This is specially useful when you need to run a coding standards check without a full Drupal installation. For example when you're checking code validation on a standalone server without a drupal site, checking a single file from a code editor (Eclipse, Textmate, etc.), or setting up pre-commit hooks to check the code on all files being committed.

Once you have run your code through these and you fixed any issue that might have come to light you're ready to commit your code knowing that it is up to par with the best.

UPDATE

If you are already using PHP_CodeSniffer to identify coding standards problems in your code, you know that fixing them by hand is tedious, especially on large projects. Well now, thanks to Fabien Potencier, creator of the Symfony framework we don't have to fix those problems by hand. PHP Coding Standards Fixer is a tool that does the job for you.

The PHP Coding Standards Fixer tool fixes most issues in your code when you want to follow the PHP coding standards as defined in the PSR-1 and PSR-2 documents.

Engineering Leadership

Get notified about updates and be the first to get short and concise articles.

By subscribing to my newsletter you accept to receive recurring emails about the services I offer and personal opinion pieces.

Proudly published using Prismic