The plugin enables analysis of PHP projects within with SonarQubeTM.
It is compatible with the Issues Report plugin to run pre-commit local analysis.
- Install the PHP Environment
- Install the plugin through the Update Center or download it into the SONARQUBE_HOME/extensions/plugins directory
- Restart the SonarQube TM server
an Analysis with the SonarQube
To run an analysis of your PHP project, use the SonarQube TM Runner.
sonar.phpPmd.skip=true sonar.phpCodesniffer.skip=true sonar.phpDepend.skip=true # Deactiving the PHP Depend plugin is highly discouraged since all the basic metrics rely on it. sonar.phpUnit.skip=true sonar.phpUnit.coverage.skip=true
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 set to
The project main test file including the relative path, ie: "/source/tests/AllTests.php". If not present, PHPUnit will look looks 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 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 (where you for a mono-module project...
#PHPMD sonar.phpPmd.analyzeOnly=true sonar.phpPmd.reportPath=path/to/myPmdReport.xml #PHP CodeSniffer sonar.phpCodesniffer.analyzeOnly=true sonar.phpCodesniffer.reportPath=path/to/myCodeSnifferReport.xml #PHP Depend sonar.phpDepend.analyzeOnly=true sonar.phpDepend.reportPath=path/to/myPhpDependReport.xml sonar.phpDepend.reportType=summary-xml #Type of report generated by PHP Depend. Valid values: summary-xml (default), phpunit-xml #PHPUnit sonar.phpUnit.analyzeOnly=true sonar.phpUnit.reportPath=path/to/myPhpUnitReport.xml sonar.phpUnit.coverage.reportPath=path/to/myCoverageReport.xml
Most of the time, using the exclusion properties will be enough to exclude files from being reported by SonarQubeTM. 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 this fileit, thus preventing SonarQube TM from completing the analysis
- a big 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 SonarQubeTM
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:
When specifying exclusions directly for each tool, you should also consider to set setting the
- 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