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
- Open PHPStorm
- Go to Setting || Alt + Ctrl + S
- Select PHP > Quality Tools > PHP_Codesniffer > Give the path of "Suizlabs/PHP_Codesniffer/bin/phpcs" Then validate it and apply
- on windows you can choose "{Magento path}\vendor\bin\phpcs.bat"
- 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
Afterward, select "magento2" from the Coding Standard dropdown and apply.
Now to configure Code styling please follow the steps below
- go to Setting || ctrl + alt + s
- Editor > Code Style > PHP : Set from > PSR1/PSR2 Apply
- Now go to any PHP file and click on "CTRL + ALT + L" to format the file