Monday, July 23, 2012

PHP Quality Metrics with Jenkins

I recently took over management of a few PHP projects and my first order of business was enhancing the code quality. Code quality means different things to different people. In my case it means relevant, thoughtful test coverage and well balanced code (a la Robert C Martin). I scoured the internet and came up with some good tools for measuring both.

See http://jenkins-php.org/http://erichogue.ca/2011/05/php/continuous-integration-in-php/, and there's even a book!

We're already using PHPUnit for our tests, but I wasn't doing any coverage analysis. That was easy to add. Next, I started using all the mess detection and robert-c-martin analysis tools. All in all, I was able to follow the directions and put a build shell script together without too much trouble.  The pieces with which I had to pay some attention were the machine setup, the jenkins project configurations, and the PHPUnit exclude options. See my gist for a sample phpunit configuration to exclude files over which you have no control, or matter not, in your project.

To save myself some trouble I put the installation steps and quality build steps into Bart, our open source project, on which all of our other projects depend (via composer). The script can be found here, https://github.com/box/bart/blob/master/build/nightly-quality-metrics.sh

Finally, my jenkins config file template can be found on github, https://gist.github.com/3168354. You can replace the template variables with their respective values for your project.

Comments welcome!

1 comment:

  1. I am surprised to know that Diesel now supports enforcing during test time that a method be registered for any requested class. I'll get back to working with diesel soon...
    php web development company

    ReplyDelete