2

I am creating a Magento 2.3 website from scratch. I am having phpcs.xml file on Magento root which contains the rules for PHPCS. These rules get triggered when the build is executed. I am confused about which rules should I use for this XML file ? Thanks in advance!

2 Answers 2

15

Funnily enough this is something I came across today and wanted to experiment.

Took me a few mins to get my head around the setup. This should get you started:

Inside web root

composer require squizlabs/php_codesniffer:^3.4
composer require magento/magento-coding-standard
vendor/bin/phpcs -i
vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/
vendor/bin/phpcs --standard=Magento2 app/code/Xigen/Extension

or dump to file

vendor/bin/phpcs --standard=Magento2 app/code/Xigen/Extension --report-file="Extension.txt"
2
  • I have added it to my setup and tried to run the phpcs, but it threw the error for app/bootstrap.php. Shouldn't it ignore this file ? Jun 6, 2019 at 5:56
  • @ParthThakkar just scan your own stuff as I have done above Jun 7, 2019 at 19:30
2

Use the official Magento PHP CodeSniffer ruleset and standards, which you can find here: https://github.com/magento/magento-coding-standard

This repository includes its own ruleset XML file that should cover everything you need.

Installation and usage directions are on the linked github page. (Not copying them in since they're liable to change over time.)

1
  • I have added it to my setup and tried to run the phpcs, but it threw the error for app/bootstrap.php. Shouldn't it ignore this file ? Jun 6, 2019 at 5:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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