Question

I like automated checks on my codebase to make sure I'm not violating style guidelines. When I worked in Perl, I would use Perl::Critic to check my style, and Test::Perl::Critic::Progressive to grandfather in any existing violations, so I could apply it to existing codebases.

Now I find myself on a PHP project. PHP CodeSniffer seems like the tool of choice in the community, but I don't see any sort of progressive mode on it.

Is There a "Progressive" mode for any PHP Style checker?

("Progressive" checking first captures a list of all existing violations, then prevents them from showing up in subsequent check runs. This means that existing violations are allowed to stay, but new ones are not allowed to be added.)

Was it helpful?

Solution

As you've found out the de-facto PHP style-checker is PHP CodeSniffer. That one does not support a progressive mode.

However, running that one with grep on the commandline is trivial so that you can start with errors and then care about warnings "progressively" at a later stage of progress.

Codesniffer integration in Eclipse (Screenshot and links) is also nice and would allow you to do something similar but just from within the IDE.

If you need something similar with not only style-checks, you can try the PHPStorm IDE which has something similar with code-inspections and allows you to differ between types of inspections and their levels. It additionally allows you to re-format your code according to your style which should help you to get the code-base into order quickly and effectively.

OTHER TIPS

I have whipped up this shell script to help:

SRCDIR=/Users/smcmillan/Documents/Development/project
WWWDIR=$SRCDIR/www

phpcs --extensions=php --report=csv "$WWWDIR" | awk -F, '{print $1, $3, $4, $5;}' > "$SRCDIR/.newerrs"

rm "$SRCDIR/.errfiles"

diff -c "$SRCDIR/.olderrs" "$SRCDIR/.newerrs" | grep ^+ | awk '{print $2}' | uniq > "$SRCDIR/.errfiles"

xargs phpcs < $SRCDIR/.errfiles 

The strategy being to capture the output of the run in csv format, and compare against an old run to get a list of the files that grew new errors. Then we send those files back to phpcs.

It's not cross-platform, and it still shows the older errors in the files that have new errors, but it's a good start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top