Actions

Difference between revisions of "Joomla CodeSniffer"

From Joomla! Documentation

(A Nose For Joomla: fixed == error)
(A Nose For Joomla)
Line 1: Line 1:
 +
(This page needs expanded installation instructions, especially for Windows-based systems.)
 +
 
== A Nose For Joomla ==
 
== A Nose For Joomla ==
  

Revision as of 17:21, 29 September 2010

(This page needs expanded installation instructions, especially for Windows-based systems.)

A Nose For Joomla

This is a custom coding standard for the PHP CodeSniffer that attempts to codify and enforce the Joomla coding standards.

Why?

The reasons seem obvious, but one look at reality shows they aren't, so I'll enumerate some of them here:

- Coherent and consisting coding practice makes the files look more professional. Conflicting styles in the same project (or worse, the same file) not only look sloppy, they encourage further sloppiness.

- When all code complies with the same standard, bad code is easier for everyone to spot.

- It makes it easier for someone new to a particular file in the project to find and fix errors, or extend functionality.

- If there is no consistent standard maintained, the sometimes developers will reformat the code to suit themselves. This causes a wide range of changes in the code repository, and if there is a later problem, a significant change could be lost in the chaff produced by a diff.

Installation

First you'll need to install phpcs (http://pear.php.net/package/PHP_CodeSniffer/download/). This set of files is intended to work with phpcs version 1.3, so behavior with any other version is undefined.

Then download and unzip the Joomla CodeSniffer, and copy the contents of it into /path/to/PHP_CodeSniffer/Standards/Joomla. (The path on some systems is /usr/lib/php/PHP/PHP_CodeSniffer but this varies from system to system. Use

pear config-get php_dir

to find out where the PEAR directory is on your system, then add "/PHP/PHP_CodeSniffer" to it.)

You invoke the custom standard by

phpcs --standard=Joomla --tab-width=4 file/to/sniff

Further documentation on the use of phpcs can be found at: [1]