magento-ecg/coding-standard 3.0

A set of PHP_CodeSniffer rules and sniffs.

Type

library

License

MIT

Requires
Requires (dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

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.

Version 3.x of phpcs is supported, for phpcs 2.x compatibility please use tagged releases

Both Magento and Magento 2 are supported.

Installation & Usage

Before starting using our coding standard install PHP_CodeSniffer.

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

composer require magento-ecg/coding-standard

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.

Requirements

PHP 5.4 and up.

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

Contribution

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