Code sniffer and Windows. Without PEAR.
I didn’t find much on the internet about installing Code Sniffer on Windows without PEAR so I decided to write this. If you are anything like me, you’ll have the machine you dev on as Windows (as unfortunately, most games are not supported on Linux yet) and your actual dev machine to be Linux; either through a virtualisation program like VirtualBox or you’re running something like ESXi on a dedicated server.
Anyway, you’ll need PHP installed locally. So go to php.net and get the version of PHP you want. I’ve gone ahead and got PHP 5.6 as I know that this works with Code Sniffer.
Extract that to a location like
C:\php\php-5.6. Add that folder onto your path. In Windows 10 it looks like this:
On a side note, the new environment variables GUI is much improved from Windows 7.
Now you’ll need a clone of the Code Sniffer repository. So
git clone git://github.com/squizlabs/PHP_CodeSniffer.git wherever you think is appropriate. I’ve put it in
C:\php\PHP_CodeSniffer. It is also worth noting that you do not need GIT installed on your Windows machine. Just clone it on your server and move it over.
You’ll need to edit the phpcs.bat file located at
Set your PHPBIN to where your PHP install is located.
if "%PHPBIN%" == "" set PHPBIN=C:\php\php-5.6\php.exe
Set the code sniffer directory to the code sniffer directory. This is the last line so mine looks like
"%PHPBIN%" "C:\php\PHP_CodeSniffer\scripts\phpcs" %*
Now, Code Sniffer is all setup! All that is left to do it setup PHPStorm (or any IDE) with it.
In PHPStorm, open the default settings or settings and search for Code Sniffer. You’ll find it under Languages & Frameworks -> PHP -> Code Sniffer. Click the button next to the configuration dropdown. Locate to your Code Sniffer path (i.e.
C:\php\PHP_CodeSniffer\scripts\phpcs.bat) and click validate. Voilà! All done.