How to setup PHP CodeSniffer on Windows machine ?
In today’s tutorial, I am demonstrating how to setup PHP CodeSniffer on Windows machine. What is the importance of CodeSniffer in your daily programming life? As per PSR-2 standards, you have to keep your coding standard same across all the developers in the universe. So PSR-2 is a common strict code style lets developers write the code that easily understood by other contributors.
This actually matters for nowadays open source frameworks as globally distributed programmers contributing to one single project. So CodeSniffer helps you to align with global standards. Most of the popular IDEs are automatically formatting your code with the latest standards. But this one lets you optimize manually with the standards.
Let’s set up the CodeSniffer in your windows machine. I’ve already setup my Xampp environment for development.
My current setup
PHP directory is C:\xampp\php
Open windows command prompt by typing cmd in Start->Run (Windows+R)
Move to your PHP installed directory
Type the installation command for CodeSniffer from pear
pear install PHP_CodeSniffer pear install --alldeps PHP_CodeSniffer
After completion of installation, verify the CodeSniffer is working by entering the command
So if you see as above, it’s installed properly in your system
As the CodeSniffer installed now you can check now the PHP files for the standard.
I have selected one random file from the development environment to test with. You can see the result in the screenshot of below.
You can read more about the CodeSniffer here