Skip to main content

Configure CodeSniffer in phpstorm for Magento2?

in this wiki, we will configure Magento 2 code standard and code styling 

First, we will configure Code Sniffer for Magento2

  1. Open PHPStorm
  2. Go to Setting ||  Alt + Ctrl + S
  3. Select PHP > Quality Tools > PHP_Codesniffer > Give the path of "Suizlabs/PHP_Codesniffer/bin/phpcs" Then validate it and apply
    1. on windows you can choose "{Magento path}\vendor\bin\phpcs.bat"
  4. Select Editor > Inspections > PHP > Quality Tools > Check the PHP_CodeSniffer validation Then in OPTIONS on the right side check all the options Give the path of "vendor/magento/magento-coding-standard/Magento2" to the Installed standards path
  5.    Afterward, select "magento2" from the Coding Standard dropdown and apply.

     

Now to configure Code styling please follow the steps below 

  1. go to Setting || ctrl + alt + s
  2. Editor > Code Style > PHP : Set from > PSR1/PSR2 Apply
  3. Now go to any PHP file and click on "CTRL + ALT + L" to format the file