PHP_CodeSniffer rules (sniffs) for Acquia coding standards

Installs: 416 812

Dependents: 9

Suggesters: 0

Security: 0

Stars: 8

Watchers: 12

Forks: 6



v0.7.0 2021-06-14 18:22 UTC

This package is auto-updated.

Last update: 2021-09-21 17:38:36 UTC


Latest Stable Version Total Downloads Latest Unstable Version License Build Status

Acquia Coding Standards for PHP is a collection of PHP_CodeSniffer rules (sniffs) for Acquia coding standards for PHP projects, including Drupal extensions.


Acquia Coding Standards for PHP includes a selection of sniffs from the following rulesets:


Rules are split into rulesets according to the project language and framework:

  • AcquiaPHP contains sniffs applicable to all PHP projects.
  • AcquiaDrupalStrict incorporates AcquiaPHP and adds all Drupal coding standards and best practices sniffs. It is recommended for new Drupal projects and teams familiar with Drupal coding standards.
  • AcquiaDrupalTransitional provides a relaxed standard for legacy Drupal codebases or teams new to Drupal coding standards. It incorporates AcquiaPHP and adds a more or less straight copy of Drupal core's own phpcs configuration, making it sufficient for core contribution.

Installation & usage

  1. Add Acquia Coding Standards for PHP to your project via Composer:

    composer require --dev acquia/coding-standards
  2. Inform PHP CodeSniffer of the location of the standard and its dependencies:

    • It is strongly recommended that you use a Composer plugin to handle this for you, e.g., DealerDirect/phpcodesniffer-composer-installer:

      composer config extra.phpcodesniffer-search-depth 4
      composer require --dev dealerdirect/phpcodesniffer-composer-installer
    • Alternatively, add a script to your composer.json to handle it:

          "scripts": {
              "post-install-cmd": "@install-coding-standards",
              "post-update-cmd" : "@install-coding-standards",
              "install-coding-standards": "\"vendor/bin/phpcs\" --config-set installed_paths vendor/acquia/coding-standards/src,vendor/drupal/coder/coder_sniffer,vendor/phpcompatibility/php-compatibility"
  3. Check code for standards compliance:

    ./vendor/bin/phpcs --standard=AcquiaDrupalStrict path/to/code

    Automatically fix any standards violations possible:

    ./vendor/bin/phpcbf --standard=AcquiaDrupalStrict path/to/code
  4. Optionally create a default configuration file for your project so you don't have to provide the command-line arguments every time (i.e., below). Here's a working example: example/phpcs.xml.dist.

  5. Optionally add code checking to your Git pre-commit hook to prevent committing code with violations. Since client-side Git hooks are not copied when a repository is cloned, you might like to use an automated solution like BrainMaestro/composer-git-hooks to manage them, for example: example/composer.json.

  6. Optionally configure PHP Code Sniffer integration in PhpStorm or your IDE or code editor of choice. You can import example/PhpStormInspections.xml to set up default integration for new projects. When you open or create a new project for the first time, PhpStorm should automatically detect and set up PHPCS inspections based on these defaults. You will just need to uncheck the “installed standards paths” in the inspection settings for your project so that PhpStorm can find the Acquia Coding Standards.


Contributions are welcome! See


Copyright (C) 2019 Acquia, Inc.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.