Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »


Jérôme Tama, Akram Ben Aissi, Frédéric Leroy, Gabriele Santini


Latest Version

0.2 ( check version compatibility )





Sonar PHP Plugin


Sonar PHP Plugin adds PHP language analysis to Sonar. The plugin provides all Sonar builtin features for PHP projects analyis. And it relies on well known analysis tools for PHP projects : PHP Unit, PHP Depend, PHPMD, PHPCPD and PHP_CodeSniffer to provide some additionnal metrics and to detect violations.

Sonar PHP Plugin

PHP Unit


PHP Depend



SQLI CodeSniffer






















Version 0.2 relies on SQLI_CodeSniffer which is derived from PHP_CodeSniffer but incompatible with the original tool.


This installation section provides two way for installing necessary tools to make the plugin work correctly. If you are familiar with an environnement, you may just need to reed the "Short way" section, if you need more help, you can follow the more verbose installation guide for the section.

Install Sonar PHP Plugin

Sonar PHP Plugin is very straight forward: Once you have installed sonar in $SONAR_HOME directoy, just copy the sonar-php-plugin.jar file inside $SONAR_HOME/extensions/plugins/ directory.

Install PHP environnement

Short way for PHP experts
  1. Install PHP runtime with the corresponding xdebug extensions. Version 5.2.6 or newer is required.
  2. Install PEAR. Version 1.8.0 or newer is required
  3. Install PHPUnit version 3.5.5 (strictly)
  4. Install phpcpd version 1.3.0 (strictly)
  5. Install PHPDepend PHPMD version 0.2.5
  6. Install PHP_CodeSniffer version 1.3.0RC1
Long way for PHP dummies
  1. Install PHP version 5.2.6 or newer. You can download PHP at this location and follow these installation instructions.
  2. Install PEAR version 1.8.0 or newer if not included in PHP distribution. To ensure pear version and to upgrade it type the following commands in command prompt:
  3. Install PHP Unit from pear using the following command lines:
  4. Install XDebug to allow code instrumentation used for instance by phpunit to compute coverage.
    • If you are running Linux or Mac you must install phpize (normally found in php dev packages like rpm php5-devel, deb php5-dev) and then compile xdebug via pecl install using the following command line
      And then edit your $PHP_HOME/cli_php.ini file to add the following line:
    • If you are running windows, you should download the binary version matching your PHP installation from this location. And then edit your $PHP_HOME/cli_php.ini file to add the following line:
  5. Install PHP Depend
  6. Install PHPMD
  7. Install PHP_CodeSniffer

Known limitations

This is an alpha version so we expect it to have a lot of bugs/uncovered cases. Please report all bugs you find on Jira.

Metrics in this version are only collected by PHP_Depend, this implies that files containing unstructured code (not OO) will not be included in this kind of analysis.
It is known that copy/paste detection is wrongly extended to comments (see #218).
The actual CodeSniffer standard used by default is just a demo one.
You can include other standards with their configuration files the "SQLI_CodeSniffer way".
We suggest you to wait for the 1.3.0 release of PHP_CodeSniffer that will bring extended configuration capabilities and will be rapidly integrated with the plugins.


com.atlassian.confluence.macro.MacroExecutionException: JIRA project does not exist or you do not have permission to view it.
  • No labels