'''NOTE''': This method is outdated, but it might be useful if you are looking for a different integration. It also demonstrates the use of external tools in PHPStorm - so it shouldn't be deleted.

+

'''NOTE''': This method is '''outdated''', but it might be useful if you are looking for a different integration. It also demonstrates the use of external tools in PHPStorm - so it ''shouldn't be deleted''.

−

<del>There is currently no plugin available</del> The CodeSniffer can also be integrated easily as an external tool. PHPStorm will display the output in the console, including clickable links containing line and column numbers to the files that contain errors.

+

The CodeSniffer can also be integrated easily as an external tool. PHPStorm will display the output in the console, including clickable links containing line and column numbers to the files that contain errors.

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?

- 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 of all you have to install the PHP CodeSniffer. This set of files is intended to work with phpcs version 1.4, so behavior with any other version is undefined. One way to do this is to start the console (cmd.exe in windows environments) and type:

pear install PHP_CodeSniffer

To specify a specific version of the PHP CodeSniffer, type:

pear install PHP_CodeSniffer-1.4.x (specify a number for x, versions 1.4.0 through 1.4.5 are available)

Pear will handle the whole installation by itself.

Then download and unzip the Joomla! CodeSniffer and copy the contents of it into /path/to/PHP_CodeSniffer/Standards/Joomla.

In Unix systems this path is usually /usr/lib/php/PHP/PHP_CodeSniffer/Standards/Joomla but this varies from system to system. In Xubuntu 12.04, the path is /usr/share/php/PHP/CodeSniffer/Standards/Joomla. Windows based system with XAMPP have the following path: PATH_TO_XAMMP\php\PEAR\PHP\CodeSniffer\Standards (for example: C:\xampp\php\PEAR\PHP\CodeSniffer\Standards)

Use

pear config-get php_dir

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

Usage

You invoke the custom standard by

phpcs --standard=Joomla file/to/sniff

To test a platform file using the provided platform coding standards use

Under Settings->Inspections when you choose joomla profile, in the tree below, search for PHP and open it and than make sure that PHP Code Sniffer validation checkbox is checked. Otherwise PHP Code Sniffer won't sniff your code.

Installing PHP PSR-0, PSR-1 and PSR-2 Sniff

unpack PSR-1 CodeSniffer rules under \xampp\php\PEAR\PHP\CodeSniffer\Standards\PSR (SPR or any directory will work)

Go to Settings (CTRL-ALT-S) and search for "PHP Code Sniffer Validation", click the button Validate to force reload of rules from disk

PSR is available in the list

PHPStorm / Alternative method

NOTE: This method is outdated, but it might be useful if you are looking for a different integration. It also demonstrates the use of external tools in PHPStorm - so it shouldn't be deleted.

The CodeSniffer can also be integrated easily as an external tool. PHPStorm will display the output in the console, including clickable links containing line and column numbers to the files that contain errors.

Click on "Settings" and search for "External tools"

Click "Add..."

Choose a "name", "Group" and "Description".

Click "Output Filters"

Click "Add...", Choose a name and enter under "Regular expression to match output" the value: $FILE_PATH$:$LINE$:$COLUMN$

"Program": Search for the phpcs executable on your system. You have to set the path to the phpcs.bat from the installed PHP_CodeSniffer PEAR package

for Unix based systems the path is something like /usr/bin/phpcs

in XAMPP (windows) you can find the file in the php root folder (e.g. C:\xampp\php\phpcs.bat)

"Paramaters":

--standard=<path/to/joomla-platform>/build/phpcs/Joomla The path to the Joomla! coding standards.

--report=emacs The will generate a simple list containing links to the error files

Optional you may want to specify -p for "progress" or -n for "errors only".

The last parameter has to be $FilePath$ specifying the file or folder you want to sniff.