In Programming world there are many tools available which can help us to improve productivity. This productivity tools can be anything which can help to reduce development time, help to improve code quality, help to track bugs easily, help to build products easily, etc.
In this article we will focus on improving Code Quality. Very first step towards improving code quality is to maintain coding standards across developers. I understand that its is really tough job to maintain the same as every developer have their own way to code stuff. e.g. some prefer all lower case for method name, some prefer camelcase for that, etc.
Very first step towards improving code quality is to maintain coding standards across developers.
Here we will talk about PHP CodeSniffer, which help us to maintain coding standard across multiple developer. Dealing with CodeSniffer is much easier: create rule set, validate your file against your rule set and get the result immediately. It will immediately show how many mistakes you have made in terms of following coding standards and eventually all developer will start coding as per coding standards you have defined.
To begin with we will start our article series with Installation of PHP CodeSniffer on Windows and Linux Server. And later we will see how we can check/validate files against rules, how we can create our own rules, etc. Hope you find this article series useful.
Note: In this article we assume that PHP is already installed in your system. So we will skip that step here.
Before we start with PHP CodeSniffer, we need to make sure PHP PEAR is installed in your system. Let’s start installing the same now.
1) Download PEAR PHAR file first from : http://pear.php.net/go-pear.phar
2) Move this file to directory where PHP is installed. In my case it is C:/PHP
3) Open a command prompt with administrative access/permission (All programs –> accessories and right-click command prompt and select “run as administrator”)
4) Now go to your PHP installation directory: cd C:\PHP
5) Its time to install PEAR now, run following command to install PEAR :
6) Next you will have to select system for install type (system is by default selected, so you can hit enter to continue.)
7) Now next step will ask you for PHP which PEAR is going to use. If you want to edit that type 11 press enter and then type c:\PHP\pear.ini
8) On this last step you need to register some environment variable in your system, which can be done by running c:\php\PEAR_ENV.reg file.
We have PHP PEAR is installed and now its time to install PHP CodeSniffer which is one of the Package of PEAR.
1) Open command prompt with administrative access.
2) Move to your PHP installation directory which is C:/PHP in my case.
3) Start installation of PHP CodeSniffer by running following command.
Once installation is done, you can execute phpcs -i in command prompt to see version of installed PHP CodeSniffer. You should get output as per below image if everything is done correct.
So far what we have done is installation of PEAR and PHP Code Sniffer on windows machine. Later we will see how to install same stuffs on Linux machine.
Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.
View all posts by: Avinash