Thursday, 23 July 2015

Setting up Squiz Labs code sniffer for PHPStorm on Windows

PHPStorm is a brilliant piece of software that's highly extensible. One of the extensions that's particularly useful is Squiz Labs' PHP Code Sniffer. It wasn't quite apparent from other documentation I found online that it's really simple to set up for Windows! So with the help of a co-worker I put together the following tutorial:

To install the code sniffer for PHPStorm:

  • Download and install PHP for Windows
  • Download https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
  • Create a file called phpcs.bat in the C:\php directory
    @echo off
    "C:\php\php.exe" -f "C:\PATH_TO_DOWNLOADED_PHAR\phpcs.phar" -- %*
  • In PHPStorm
    • Open File->Settings
    • Select Languages & Frameworks->PHP
      • Add a local interpreter that points to C:\php\php.exe
      • Select Languages & Frameworks->PHP->Code Sniffer
      • Update the local configuration to point to C:\php\phpcs.bat
        • increase the Tool process timeout if you're working on remote code
    • Click Validate to ensure that the code sniffer is loaded correctly
    • Click Apply
    • Select Editor->Inspections
      • Select the checkbox for PHP Code Sniffer validation
      • Select PHP Code Sniffer validation
      • Set the coding standard (you'll probably want PSR2)
    • To run the code sniffer
      • Press CTRL + ALT + SHIFT + I
      • Type "code sniffer" and press enter
      • Select the current file
And there you go!

No comments:

Post a Comment

@mysql/xdevapi joy!

after hitting a wall last night with the existing node.js mysql packages, which for some reason have been years behind integrating with mysq...