Friday, 8 February 2008

PHP_CodeSniffer task is in the current Phing branch

A few days ago I was evaluating the need for writing a Phing task for the awesome PHP_CodeSniffer Pear package and noticed that Dirk Thomas blessedly already added one to the current Phing Svn branch. That's again extending the range of available tools that PHP's Continuous Integration(CI) toolchain has to offer and I quess there are more to follow, as Manuel Pichler just announced the development start of PHP_Depend.

To get the 2.3 Phing branch including the mentioned PHP_CodeSniffer task and it's documentation simply run a svn checkout http://svn.phing.info/branches/2.3 /path/to/phing-checkout-dir and you're ready to add continuous monitoring of coding standard adherence to your builds.

For simplifying the integration of the just checked out Phing 'branch' release into an existing Pear environment you can build a new Pear package by calling the buildfile in /path/to/phing-checkout-dir/pear. The built Pear package will be located in /path/to/phing-checkout-dir/pear/build and can than be used to switch the installed Phing Pear release.

Also make sure you have installed the underlying PHP_CodeSniffer Pear package via the Pear Installer.

Although the task is very well documented the next code snippet shows the shiny PHP_CodeSniffer task in an example build file.

<?xml version="1.0"?>
<project name="example" default="build" basedir=".">

<target name="build" depends="clean, svn-checkout, code-inspection, test">

...

</target>

...

<target name="code-inspection" description="runs code inspection on the stated directory">
<phpcodesniffer standard="PEAR"
format="summary"
tabWidth="4"
file="/path/to/source-files"
allowedFileExtensions="php"/>
</phpcodesniffer>
</target>

</project>

3 comments:

Anonymous said...

I have recently started using Phing to automate PHP project builds, and am using a number of the current built-in tasks. I have been missing the CodeSniffer one though - you say it has been added to the current branch, is there any estimate on when that will become a release?

Raphael Stolt said...

Hi Grant,
thanks for stopping by. There is currently no exact release date for Phing 2.3.1 available, but there is a RC1 available and according to the changelog it already includes PHP_CodeSniffer task.

Anonymous said...

Thanks for the response. I guess it is just a matter of time before it is officially released. I decided to be adventurous and installed via the instructions int he post. It worked as expected, and I now have a pretty good Phing build file put together.