Skip to content

PHPCS - PHP Code Sniffer

PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent.

DrevOps comes with pre-configured PHPCS ruleset for Drupal projects.


Check for violations

ahoy lint-be

Fix violations

ahoy lint-fix


See configuration reference.

All global configuration takes place in the phpcs.xml file.

By default, PHPCS will check against the following rules:

  • Drupal
  • DrupalPractice
  • Generic.Debug.ESLint
  • PHPCompatibility

Targets include custom modules and themes, settings and tests.

Adding or removing targets:


Run checks against platform version specified in composer.json key config.platform.php:

<config name="testVersion" value="8.1"/>


Ignoring rules globally takes place in the phpcs.xml file:

<!-- Comment about why this rules is excluded. -->
<rule ref="DrupalPractice.General.ClassName.ClassPrefix">

To ignore all PHPCS rules within a file, place in the file header:

// phpcs:ignoreFile

To ignore a specific rule within a file, place in the file header:

// phpcs:disable <rule_name>

To ignore rule for the code block:

// phpcs:disable <rule_name>
$a = 1;
// phpcs:enable <rule_name>

To ignore only the current and the next line:

// phpcs:ignore
$a = 1;

Ignoring fail in CI

This tool runs in CI by default and fails the build if there are any violations.

Set DREVOPS_CI_PHPCS_IGNORE_FAILURE environment variable to 1 to ignore failures. The tool will still run and report violations, if any.