Skip to content
Magento PHP_CodeSniffer Coding Standard
Branch: master
Clone or download
Latest commit 7ead7ce Aug 8, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
Ecg Refactor UnitTests for PHPCodeSniffer 3.0 compatibility May 20, 2017
EcgM2 Refactor UnitTests for PHPCodeSniffer 3.0 compatibility May 20, 2017
.gitignore Change folder structure Dec 17, 2015
LICENSE Fix README syntax May 14, 2017 Update Aug 8, 2017
composer.json Revert "Add PHP_Codesniffer to require" Jun 30, 2017

ECG Magento Code Sniffer Coding Standard

SensioLabsInsight Medal

ECG Magento Code Sniffer Coding Standard is a set of rules and sniffs for PHP_CodeSniffer tool.

It allows automatically check your code against some of the common Magento and PHP coding issues, like:

  • raw SQL queries;
  • SQL queries inside a loop;
  • direct instantiation of Mage and Enterprise classes;
  • unnecessary collection loading;
  • excessive code complexity;
  • use of dangerous functions;
  • use of PHP Superglobals;

and many others.

Both Magento and Magento 2 are supported.


Before starting using our coding standard install PHP_CodeSniffer.

The recommended installation method for PHPCS is globally with Composer:

composer global require "squizlabs/php_codesniffer=*"

Make sure Composer's bin directory (defaulted to ~/.composer/vendor/bin/) is in your PATH.

Clone or download this repo somewhere on your computer or install it with Composer:

composer require magento-ecg/coding-standard

Note: PHP_CodeSniffer 3.x is now required to run our coding standard. To install PHP_CodeSniffer 2.x compatible version:

composer require magento-ecg/coding-standard:2.*

Note: Alternatively to installing PHP_CodeSniffer globally, you can include dependencies for both magento-ecg/coding-standard and squizlabs/php_codesniffer in your composer.json file. For example:

    "require": {
        "magento-ecg/coding-standard": ">=3.0",
        "squizlabs/php_codesniffer": "3.*"


Select a standard to run with CodeSniffer:

  • Ecg for Magento
  • EcgM2 for Magento 2

Run CodeSniffer:

$ phpcs --standard=./vendor/magento-ecg/coding-standard/Ecg /path/to/code
$ phpcs --standard=./vendor/magento-ecg/coding-standard/EcgM2 /path/to/code

As a one time thing, you can add the ECG standards directory to PHP_CodeSniffer's installed paths:

$ phpcs --config-set installed_paths /path/to/your/folder/vendor/magento-ecg/coding-standard

After that specifying the path to a standard is optional:

$ phpcs --standard=Ecg /path/to/code
$ phpcs --standard=EcgM2 /path/to/code

PHP CodeSniffer will automatically scan Magento PHP files. To check design templates, you must specify phtml in the --extensions argument: --extensions=php,phtml.


PHP 5.4 and up.

Checkout the php-5.3-compatible branch to get the PHP 5.3 version.


Please feel free to contribute new sniffs or any fixes or improvements for the existing ones.

You can’t perform that action at this time.