Code sniffers
We recommend the consistent use of a code sniffer to enhance the readability of your code and help ensure that it meets Magento code standards. A code sniffer is a tool that automates the process of identifying code irregularities. Although a sniffer will identify many more inconsistencies and errors than a manual edit, we recommend that you evaluate and make any fixes that your sniffer program identifies.
Magento recommends the use of PHP_CodeSniffer, the most popular code sniffer in use throughout the PHP development community. PHP_CodeSniffer 1.4.0+ includes PSR-1 and PSR-2 standards, which are followed by Magento 2. You can configure PHP_CodeSniffer to use your own rules, too. The Magento Extension Quality Program Coding Standard provides specifications that you can use to configure your code sniffer of choice to bring your PHP coding style closer to Magento PHP standards.
Rule set for the PHP_CodeSniffer
You can use our custom rule set with the code sniffer to be confident that your code meets all Magento-specific standards.
The rule set is located in dev/tests/static/framework/Magento/ruleset.xml
.
Learn more about using rule sets with PHP CodeSniffer
Code standards
Magento supports the PSR-1 and PSR-2 standards.
The Coding standards overview introduces Magento-specific practices for PHP, JavaScript, and JQuery.