Categorized | News, PHP

PHP Coding Standards – Laying Down the Law

Posted on 20 September 2006 by Demian Turner

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.

Bookmark and Share

5 Comments For This Post

  1. Lars Pohlmann Says:

    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.

  2. Demian Turner Says:

    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.

  3. Savadeep Speaks! Says:

    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…

  4. Webdigity webmaster forum Says:

    Just read here about CodeSniffer, a PEAR package that parses

  5. Lucas Bickel Says:

    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…

Leave a Reply

Categories

Books

Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists

Facebook