Thursday, 3 July 2008

PHP_CodeSniffer update

It's been a while since I've posted about PHP_CodeSniffer, which is probably because nothing of great interest has been happening in the project. I'm pushing forward for a 1.1.0 stable release (the first stable with JavaScript code sniffing support) and have just released version 1.1.0RC3. I'm hoping that this will be the last release candidate before the stable.

So it's been a fairly boring period of time where I haven't wanted to add any new features for fear of destabilising the code, but some changes are on the horizon now, and they should be welcome additions.

The first of these is copy/paste detection, allowing PHP_CodeSniffer to find duplicate code throughout a project and help implement some code reuse. This is a feature PHPUnit currently has, but Sebastian Bergmann has kindly offered to port it to PHP_CodeSniffer as it seems like a better fit for this particular QA feature.

To implement this, I'll be creating a new kind of sniff that will be run after all files have been sniffed. It will be passed PHP_CodeSniffer_File objects for every file tested during the run, allowing the sniff to look into each file and do project-level checking. Errors will still be reported per file, as they are now.

The other feature PHP_CodeSniffer seems destined to get is the separation of the main code sniffing core from the standards. Coding standards can already be run without having to live inside the PHP_CodeSniffer standards directory (more on that later) but unit tests can not be correctly run in this scenario. This feature should make it easier for developers to distribute their own coding standards and introduce dependencies between standards and the core.

I have tried doing this before, but I could never get the PEAR installer to write the unit tests to the directory I wanted so I could run all my tests at once. Helgi Þormar Þorbjörnsson has kindly offered to help me resolve my unit testing problems, so I'll hopefully be able to sort out this issue now.

Finally, Stefan Priebsch got a bit fed up with my crappy documentation for external standards and decided to (thankfully) write an article about how to use an external standard with PHP_CodeSniffer. Well worth a read if you're managing your own coding standard. You might even be learning about this little used feature for the first time.