PHP code metrics in CLI and Jenkins

Posted by Sami Tikka on August 14, 2013

Continuous integration template is an ant script for running common PHP code metrics in CLI and Jenkins. Script is built for Symfony projects, as it targets /src folder automatically, but can be modified for any PHP project.

Code metrics? What?

You should. Some of the better tools:

  • phploc: Gives you among other info lines of code (LOC), cyclomatic complexity etc. In itself, these numbers may not tell much, but they become useful when history data is kept and graphed.
  • phpmd: Very useful tool, that gives you clear suggestions for improving the code, line by line. Suggestions are defined in rulesets, that cover code base size, design, accessing superglobals etc. issues.
  • phpcpd: Find copy paste code!
  • phpcs: Keep an eye on coding standards. PSR-2 is highly recommended.

These and more are preconfigured in the template. Comments and pull requests are very welcome.