Tuesday 18 September 2007

PHP_CodeSniffer and the Zend Code Analyzer

Ever since I first used the Zend Code Analyzer, I've wanted to put it into our code sniffers, but I've never got around to doing it. Now, thanks to a contribution from Holger Kral of Zend, and a new config system in PHP_CodeSniffer, you can include ZCA warnings in your coding standards.

I've just committed the CodeAnalyzer sniff into the Zend standard under a new Debug category. The sniff requires you to have ZCA installed on the same machine as PHP_CodeSniffer, and you need to tell PHP_CodeSniffer where to find it.

$ phpcs --config-set zend_ca_path /path/to/ZendCodeAnalyzer
$ phpcs --standard=zend /path/to/file
Zend Code Analyzer produces warnings for things like unused function arguments and unreachable code. Not all the warnings need to be fixed, but it can certainly find some common mistakes in your code.