1

We developed a module for Magento 2 and we would like the coding standards to match magento 2 coding standard( no warnings or errors ).

Magento 2 has some additional standards that it runs through once you submit a module, we would like that ruleset.xml We are already using PSR2.

By the way this slightly breaks the rules of StackExchange, but I think it would be a valuable asset to any M2 extension developer.

1

I believe this is what you are looking for: https://github.com/magento-ecg/coding-standard

This is an added ruleset for PHP_CodeSniffer with Magento ECG (Expert Consulting Group)'s additional standards. The github page includes full directions on installation and usage. If you use an IDE with PHPCS support (like PhpStorm), you can set it up to apply the EcgM2 standard without much difficulty.

Note that the Marketplace code verification process does not exactly match the ECG ruleset (yet; they're working on that), and that it covers some things the ruleset couldn't possibly (like plagiarism).

1

Magento2 follows the PSR-2 coding standards.

So you can use PHPCS to scan for coding standard violations.

./vendor/bin/phpcs -n --standard="PSR2" ./app/code/<Vendor>/<ModuleName>/*

But magento has written its own custom rules over the PSR2 standards so you can try the following as well

./vendor/bin/phpcs --standard="./dev/tests/static/testsuite/Magento/Test/Php/_files/phpcs/" ./app/code/<Vendor>/<ModuleName>/*

Next if you looking for code audit tool you can use Magento ECG for Magento2

Also for module verification there is a different script available You can read the details here

  • It also adds some other standards :) – Olavi Sau Jun 27 '16 at 12:38
  • @OlaviSau you can have a look to the file .php_cs present in the root of the magento installation, it is the default PHPCS check hook that magento recommends to use. – Atish Goswami Jun 27 '16 at 12:57
  • @OlaviSau I have updated by answer please check if that helps ..... – Atish Goswami Sep 14 '16 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.