Description / Features
The plugin enables analysis of PHP projects with SonarQube.
It relies on well-known external tools: PHPUnit, PHP Depend, PHPMD and PHP CodeSniffer.
- Install the PHP Environment
- Install the plugin through the Update Center or download it into the SONARQUBE_HOME/extensions/plugins directory
- Restart the SonarQube server
Run an Analysis with the SonarQube Runner (Recommended method)
To run an analysis of your PHP project, use the SonarQube Runner.
You can also have a look at the SonarQube Runner documentation page to define a multi-module PHP project.
Run an Analysis with the other Analyzers
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 SonarQube
To configure the execution of PHPUnit, it is recommended to create a configuration file and set the path to this file with the
If a configuration file is not used, the following property can be set to configure the execution of PHPUnit:
If set to
The project main test file including the relative path, ie: /source/tests/AllTests.php. If not present, PHPUnit looks for phpunit.xml in the test directory.
Ignore the unit tests files matching this pattern.
Use this bootsrap file to initialize the unit tests.
If set to
|Only runs tests from the specified group(s).|
|To specify which |
Reusing existing reports
To reuse existing reports from PHP Depend, PHPUnit, etc.:
- Set the
- Set the path to the report in
sonar.<external_tool>.reportPath. Path is relative to the base directory.
Most of the time, using the exclusion properties will be enough to exclude files from being reported by SonarQube. 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) because:
- a file is badly written and the tool is crashing when analyzing it, thus preventing SonarQube from completing the analysis
- a large 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 SonarQube
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.
See PHP FAQ.
Extending Coding Rules
See the tutorial to extend coding rules with PHP CodeSniffer and/or PHPMD.
- PHP 1.2 - short-term activity (see the JIRA open tickets)
- Improve the PHP CodeSniffer rule repository (adding missing parameters, descriptions, ...)
- Work on the "Sonar Way", PEAR and Zend profiles (<= for PHP gurus! )
- PHP 2.0 - mid-term activity
- Handle multiple files with the same name
- Consider root folders as "Projects"
- Non structured PHP files
- If it turns out that those tickets are technically difficult/long to implement, then they can be postponed