Squiz Labs Blog - The latest news from the R&D arm of Squiz®

Subscribe to our RSS feeds

PHP_CodeSniffer interactive mode

PHP_CodeSniffer is traditionally run over a set of files and a report printed after the run. A developer then uses the report to fix the errors and rechecks the files manually. This can be quite time consuming for large code bases because the error list may be long or may change as other errors are fixed. To make this process easier, a new interactive mode has just been committed to the PHP_CodeSniffer SVN repository.

When PHP_CodeSniffer is asked to run interactively, it will stop checking files as soon as it finds one with errors. It will then print the error report for this file and wait for user input. The idea here is that you go away, fix the errors in the file (focusing on one file at a time) and then ask PHP_CodeSniffer to recheck the file. If the errors are now gone, PHP_CodeSniffer will continue checking the code base from where it left off. If more errors are found, the new error report is shown for the file. You also have to option of skipping the file if you would prefer to fix the errors later.

The following example shows some sample output from interactive mode. This mode is enabled using the -a command line argument.

$ phpcs -a temp.php

FILE: /Users/gsherwood/PHP_CodeSniffer/trunk/temp.php
--------------------------------------------------------------------------
FOUND 2 ERROR(S) AND 1 WARNING(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------
 2 | WARNING | Inline control structures are discouraged
 2 | ERROR   | Missing file doc comment
 2 | ERROR   | TRUE, FALSE and NULL must be lowercase; expected "true" but
   |         | found "TRUE"
--------------------------------------------------------------------------

<ENTER> to recheck, [s] to skip or [q] to quit :

Interactive mode also works with all other PHP_CodeSniffer command line options. So you can set the report format and standard to use, if you want to hide warnings, if you'd like to display verbose output, which files to ignore, etc.

So grab a copy of PHP_CodeSniffer from the SVN repository and give it a go. Just add -a to your normal PHP_CodeSniffer command. If you prefer to wait until the release, this feature will be in version 1.2.3 and released as stable in a few weeks time.

Squizlabs

Squiz Labs is the research and development arm of Squiz, the company behind the MySource Matrix and MySource Mini open source content management systems.

Our PHP and JavaScript developers are responsible for producing innovative enterprise-quality software while our interface designers and testing team ensure our products both look great and are easy to use.

Take a look at our product line-up:

MySource Matrix

MySource Matrix is a robust, scalable Content Management solution for the enterprise. It competes effectively with and surpasses the offerings of other CMS's such as Vignette and Interwoven.

Read Articles | Visit Website

MySource Mini

MySource Mini is the next generation CMS from Squiz boasting the first true inline editing experience. Simplicity is the key to MySource Mini with enterprise features as easy to use as common editing tools.

Read Articles | Visit Website

PHP_CodeSniffer

PHP_CodeSniffer is a tool that tokenises and sniffs PHP, JavaScript and CSS files to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent.

Read Articles | Visit Website