Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save emilushi/43a0bff63b89dc01dd96628b2dabba8c to your computer and use it in GitHub Desktop.
Save emilushi/43a0bff63b89dc01dd96628b2dabba8c to your computer and use it in GitHub Desktop.
Step by step guide how to setup PhpStorm with PHP_CodeSniffer and WordPress Coding Standards

Please follow the above steps to setup PhpStorm with PHP CodeSniffer and WordPress Coding Standards.

The first step is only for PhpStorm and doesn't do all the work

  1. Open Preferences menu on PhpStorm from there find the Editor menu and navigate to Code Style > PHP
    1. in the top right corner click on Set From and select WordPress from the drop-down menu WP Coding Standards
  2. Install composer globally if you don't have it installed already with the following commands.
    1. Check official documentation how to install composer on your machine here or follow the below steps if your on Linux,Unix or macOs
    2.    # 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
  3. Install PHP_CodeSniffer globally using composer
    1. composer global require "squizlabs/php_codesniffer=*"
  4. Install WordPress Coding Standards
    1. composer global require wp-coding-standards/wpcs
  5. Configure PhpStorm to use PHP_CodeSniffer and WordPress Coding Standards
    1. Open Preferences > PHP > Quality Tools and open PHP_CodeSniffer drop-down
    2. on Configuration click the ... to create a new instance
    3. a popup window will open PhpStorm Popup Window
      1. 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
      2. 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
      3. once you added these click Ok. PhpStorm ScreenRec
    4. Enable inspections for PHP_CodeSniffer by opening Preferences > Editor > Inspections
      1. On the inspections window look for PHP > Quality Tools > PHP_CodeSniffer and enable it by checking the checkbox on the right. PhpStorm Screenshot

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment