views:

620

answers:

2

Are there any existing tools for applying an arbitrary lint to PHP code? I know about the command line flag (-l) and pecl extension that will check an input file for valid syntax. What I want is a tool that will let me reject something if it has a certain valid but undesirable syntax.

For example, the lint might reject this

if ($foo) bar();

but accept this

if ($foo) {
    bar();
}

Both are "valid code", but the first break my personal coding conventions.

+6  A: 

PHP CodeSniffer does this: http://pear.php.net/package/PHP_CodeSniffer

There are some predefined conventions (like PEAR, Zend etc) and you can also very easily create your own. You can basically add a set of rules (they call them sniffs) into a group called a standard. It is also possible to include sniffs from another standard so you can easily define your own standard with existing rules.

I use this in combination with a CruiseControl continuous integration setup and it works well.

eamelink
A: 

does a tool which reformat (not entirely) a php code according to some simple rules exist? thx

Guillaume Aversa