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 126 Next »

Live example


If you want to see a live example of the capabilities of the PHP plugin, you can have a look at the analysis of the PHP CodeSniffer project on Nemo.

Description / Features

The plugin enables analysis of PHP projects within Sonar.

It is compatible with the Issues Report plugin to run pre-commit local analysis.

It relies on well-known external tools: PHPUnit, PHP Depend, PHPMD and PHP CodeSniffer.


  1. Install the PHP Environment
  2. Install the Sonar PHP plugin through the Update Center or download it into the SONAR_HOME/extensions/plugins directory
  3. Restart the Sonar server


Run a Sonar Analysis with the Sonar Runner (Recommended Way)

To launch a Sonar analysis of your PHP project, use the Sonar Runner.

Sample projects are available on GitHub that can be browsed or downloaded: /projects/languages/php.

You can also have a look at the Sonar Runner documentation page to define a multi-module PHP project.

Run a Sonar Analysis with the other Analyzers

Maven and Ant can also be used to launch analysis on PHP projects.

Advanced Settings

Disabling or enabling external tools on demand

It is possible to disable each external tool. By default, all the external tools are enabled.

Configuring PHPUnit to be run by Sonar

To configure the execution of PHPUnit, it is recommended to create a configuration file and set the path to this file with the sonar.phpUnit.configuration property.

If a configuration file is not used, the following property can be set to configure the execution of PHPUnit:


Default value




If true, PHPUnit will ignore any phpunit.xml file for launching the unit tests.
If false, PHPUnit will use any existing phpunit.xml file in the running directory.



The project main test file including the relative path, ie: "/source/tests/AllTests.php". If not present, PHPUnit will look for phpunit.xml file in the test directory.



Ignore the unit tests files matching this pattern.



Use this bootsrap file to initialize the unit tests.


If true, Sonar PHP will append test directory to PHPUnit. This will make PHPUnit look for test cases inside this directory. If several directories are defined as test directories, a phpunitRANDOM.xml file will be generated and passed to phpunit --configuration=. This generated file will contain all files inside the test directories. Only runs tests from the specified group(s).
sonar.phpUnit.loader To specify which TestSuiteLoader implementation to use.

Reusing existing reports

To reuse existing reports from PHP Depend, PHPUnit, etc.:

  1. Set the sonar.<external_tool>.analyzeOnly property to true
  2. Set the path to the report in sonar.<external_tool>.reportPath. Path is relative to the base directory (where you for a mono-module project...

Excluding files

Most of the time, using the sonar.exclusions property will be enough to exclude files from being reported by Sonar. However, there might be some cases where you really want to exclude files from being analyzed by an external tool (may it be PHP CodeSniffer,  PHPMD or PHP Depend):

  • a file is badly written and the tool is crashing when analyzing this file, thus preventing Sonar from completing the analysis
  • a big number of files must be excluded and there's no need for the external tools to spend time analyzing files that won't be reported in Sonar

For these specific cases, you should use the sonar.xxxx.argumentLine property of the external tool to manually define exclusions. For instance, for PHP CodeSniffer, you would add the following property:

This would tell PHP CodeSniffer to ignore every PHP file located in the Database folder.

Be carefull!


When specifying exclusions directly for each tool, you should also consider to set the sonar.exclusions property accordingly. Otherwise, you may have files with incomplete analysis.




See Metrics documentation page.

Extending Coding Rules

See the tutorial to extend coding rules with PHP CodeSniffer and/or PHPMD.


  1. PHP 1.2 - short-term activity (see the JIRA open tickets)
    1. Improve the PHP CodeSniffer rule repository (adding missing parameters, descriptions, ...)
    2. Work on the "Sonar Way", PEAR and Zend profiles (<= for PHP gurus! (wink) )
  2. PHP 2.0 - mid-term activity
    1. Handle multiple files with the same name
    2. Consider root folders as "Projects"
    3. Non structured PHP files
    4. If it turns out that those tickets are technically difficult/long to implement, then they can be postponed

Change Log

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


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


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


  • No labels