Please follow the above steps to setup PhpStorm with PHP CodeSniffer and WordPress Coding Standards.
- Open Preferences menu on PhpStorm from there find the Editor menu and navigate to Code Style > PHP
- Install composer globally if you don't have it installed already with the following commands.
- Check official documentation how to install composer on your machine here or follow the below steps if your on Linux,Unix or macOs
-
# This is the fastest way for Linux/Unix and macOs $ curl -sS https://getcomposer.org/installer | php # this will download composer binary file and generate a composer.phar on the current directory $ mv composer.phar /usr/local/bin/composer # move composer.phar from current directory under bin directory so it will be available globally and change its name from composer.phar to composer so it will easy to use as command. $ chmod +x /usr/local/bin/composer # set executable permission to current user for the composer file
- Install PHP_CodeSniffer globally using composer
composer global require "squizlabs/php_codesniffer=*"
- Install WordPress Coding Standards
composer global require wp-coding-standards/wpcs
- Configure PhpStorm to use PHP_CodeSniffer and WordPress Coding Standards
- Open Preferences > PHP > Quality Tools and open PHP_CodeSniffer drop-down
- on Configuration click the ... to create a new instance
- a popup window will open
- where it says PHP_CodeSniffer path add the executable file for PHP_CodeSniffer it should be something like:
.composer/vendor/squizlabs/php_codesniffer/bin/phpcs
but this depends on where you have installed composer and PHP_CodeSniffer adn your OS - where is says Path to phpcbf add the executable file for PHP_CodeSniffer beautifier it should be something like:
.composer/vendor/squizlabs/php_codesniffer/bin/phpcbf
but this depends on where you have installed composer and PHP_CodeSniffer and your OS - once you added these click Ok.
- where it says PHP_CodeSniffer path add the executable file for PHP_CodeSniffer it should be something like:
- Enable inspections for PHP_CodeSniffer by opening Preferences > Editor > Inspections
Once done with all the steps you will be ready to use WordPress Coding Standards from PhpStorm, this will highlight your code as warning if your code doesn't meet the required standards and as well will show tips how to improve the code and even help you to format the code using phpcbf (PHP Code Beautifier and Fixer)
Great.
Back to work now :P