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
Windows 10
Xampp
PHP directory is C:\xampp\php
Step 1
Open windows command prompt by typing cmd in Start->Run (Windows+R)
Move to your PHP installed directory
cd C:\xampp\php
Step 2
Type the installation command for CodeSniffer from pear
pear install PHP_CodeSniffer
pear install --alldeps PHP_CodeSniffer
Step 3
After completion of installation, verify the CodeSniffer is working by entering the command
phpcs -i
So if you see as above, it’s installed properly in your system
Step 4
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
- Just want to thank us? Buy us a Coffee
- May be another day? Shop on Amazon using our links.
Your prices won't change but we get a small commission.
Leave a Reply