To check Magento 2.x code use Consolidated Magento Coding Standard.
Magento EQP 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:
Magento Extension Quality Program Coding Standard consists of one ruleset - MEQP1 for Magento 1.x.
Install all dependencies via Composer:
$ composer create-project --repository=https://repo.magento.com magento/marketplace-eqp magento-coding-standard
You’re required to authenticate; see Get your authentication keys for details.
$ cd magento-coding-standard
Select the standard to run with PHP_CodeSniffer. To check Magento extension run:
$ vendor/bin/phpcs /path/to/your/extension --standard=MEQP1
By default, PHP_CodeSniffer will check any file it finds with a .inc
, .php
, .js
or .css
extension. To check design templates you can specify --extensions=php,phtml
option.
To check syntax with specific PHP version set paths to php binary dir:
$ vendor/bin/phpcs --config-set php7.0_path /path/to/your/php7
$ vendor/bin/phpcs --config-set php5.4_path /path/to/your/php5.4
PHP_CodeSniffer offers the PHP Code Beautifier and Fixer (phpcbf
) tool. It can be used in place of phpcs
to automatically generate and fix all fixable issues. We highly recommend run following command to fix as many sniff violations as possible:
$ vendor/bin/phpcbf /path/to/your/extension --standard=MEQP1
To make sure your extension will pass CodeSniffer checks of Magento Marketplace Technical Review, you could run phpcs
command with --severity=10
option.
$ vendor/bin/phpcs /path/to/your/extension --standard=MEQP1 --severity=10 --extensions=php,phtml
All severity 10 errors must be fixed in order to successfully pass Level 1 CodeSniffer checks.
Notice: PHP and Composer should be accessible globally.
Please feel free to contribute new sniffs or any fixes or improvements for the existing ones.