PHP_CodeSniffer is a PHP5 script that tokenises and "sniffs" PHP and JavaScript code to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.
Download:
http://pear.php.net/package/PHP_CodeSniffer/download
Install:
pear install PHP_CodeSniffer
Using:
phpcs /path/to/code/my_dir
Using TextMate with PHP_CodeSniffer.
Quick Start
1. Install PHP command line.
2. Install PHP_CodeSniffer PEAR package.
3. Download PHP_CodeSniffer command v0.1 from here.
4. Unzip the downloaded file.
5. Install the bundle by double clicking the icon.
Once the bundle is installed, you have to update two lines of code to make it work in your system.
One is the path to php executable file on the first line of the code. The typical location on OS X is /usr/bin/php.
Next, you need to change the path to PHP_CodeSniffer installation. In most of systems, ‘/usr/bin/phpcs’ would work just fine.
Now you are ready to go. Try to open your PHP code in TextMate, then the default setup will let you run the command by pressing ‘Shift + Apple Key + C’. It will display the output window like:
Introduction
I have been a PHP developer more than 2 years now and have been using JEdit as primary text editor until recently I switched to TextMate. Despite of excellent editing power and numerous great plugins, the slow nature of Java really put me down and has been consistently irritating. After several trials on various alternative text editors on mac, I ended up using TextMate that satisfies me good enough to give up good old JEdit.
During my daily coding duties, I use PHP_CodeSniffer (a.k.a phpcs) to validate my PHPcode against my company’s coding standards, typically on the command line using Terminal. Only the problem is that I have to type the path to the file name whenever I need update different files. It is not really efficient especially you are working on big project with many many files. Thankfully ‘Commands’ in TextMate gave me a nice nifty shortcut to run phpcs on without jumping to Terminal app.
One of the biggest advantage of using TextMate is Commands. It is a powerful tool that TextMate can have certain level of integration with external scripts. What phpcs_cmd does is simply to run PHP_CodeSniffer on your opened PHP source code, then displays the result in HTML format. The command itself is also written in PHP.
Using PHP_CodeSniffer
PHP_CodeSniffer is PEAR package that tokenises and “sniffs” PHP code to detect violations of a defined set of coding standards. It is an essential development tool that ensures that your code remains clean and consistent. It can even help prevent some common semantic errors made by developers. It is now used by PEAR community. Every PEAR code is checked by PHP_CodeSniffer everyday and reports the errors to developers.
You can find the documentation for more details on PEAR website or Greg Sherwood’s blog who is the maintainer of this package.
No comments:
Post a Comment