There was a fantastic CS helper package released at PEAR this week, PHP_CodeSniffer. The package, which requires PHP5 and is nicely coded, puts a phpcs script in your path so you can pass files or directories to it to get your CS validated.
The results are detailed and processing is surprisingly fast considering how many tokens are being parsed.
[demian@localhost lib]$ phpcs -v SGL.php
Registering sniffs… DONE
Processing SGL.php [2587 tokens in 425 lines]… DONE in < 1 second
Typical CS errors/warnings look like this, I just fixed the errors in this case
PHP_CodeSniffer is a godsend when you’re in the position of having to explain what PHP coding standards are the newbies on average twice/week, and what the difference is between conditional and method bracing, etc, etc.
As we’ve seen ZDE and various other IDEs bundle other PEAR packages with their software like phpDocumentor, I hope this tool too becomes a standard IDE helper in the near future.
Hats off to Squiz for putting PHP_CodeSniffer together.








September 20th, 2006 at 3:38 pm
I’ve been looking for something like this for a long time. I’ve been working with a hacked (by me) Version of PHPCheckstyle – http://developer.spikesource.com/wiki/index.php/Projects:phpcheckstyle
But the project seems to be dead. Let’s hope, this is going to be more alive. Automated checking for CS in a company is quite important.
September 20th, 2006 at 5:38 pm
at first go this project seems quite impressive, i’d like to hear your feedback. what would be great would be great would be to setup an svn post-commit hook to run the sniffer on code changes and dispatch some kind of alert when errors are detected.
September 21st, 2006 at 3:13 am
Myself, I am but not much a liker of PHP. But my readers, I am of the know that many of you are but not only users of PHP for your own developments, but a user of PHP you are in the form of so many World Wide Web softwares and services. Especially to…
September 21st, 2006 at 9:45 am
Just read here about CodeSniffer, a PEAR package that parses
January 30th, 2007 at 4:22 pm
phing integration would also be nice…
maybe i’ll give this a shot. OTOH it seems that i might have similar difficulties to the ones phpunit and its phing integration have. imho the hard part is deciding who does what. (ie. should phing make reports or delegate it to tasks)
this post might sound quite confused, i’ll probablly write a longer (blog-)article on the whole dev-infrastructure stuff. CS is definitively gonna get mentioned…