{iframe:src=http://update.sonarsource.org/plugins/php.html|width=700|height=250|frameborder=0}
Your browser does not support iframes.
{iframe} |
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. |
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.
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.
Maven and Ant can also be used to launch analysis on PHP projects.
It is possible to disable each external tool. By default, all the external tools are enabled.
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 |
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:
Key | Default value | Description |
|---|---|---|
sonar.phpUnit.ignore.configuration | false | If true, PHPUnit will ignore any phpunit.xml file for launching the unit tests. |
sonar.phpUnit.mainTestClass |
| 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. |
sonar.phpUnit.filter |
| Ignore the unit tests files matching this pattern. |
sonar.phpUnit.bootstrap |
| Use this bootsrap file to initialize the unit tests. |
sonar.phpUnit.analyze.test.directory | true | 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. |
| sonar.phpUnit.group | Only runs tests from the specified group(s). | |
| sonar.phpUnit.loader | To specify which TestSuiteLoader implementation to use. |
To reuse existing reports from PHP Depend, PHPUnit, etc.:
#PHPMD sonar.phpPmd.analyzeOnly=true sonar.phpPmd.reportFileName=myPmdReport.xml #default is logs; parent is $PROJECT_HOME/.sonar/target when the analysis is triggered with the Sonar Runner, $PROJECT_HOME/target when triggered with Maven sonar.phpPmd.reportFileRelativePath=<relative_path_from_parent_to_xml_report> #PHP_CodeSniffer sonar.phpCodesniffer.analyzeOnly=true sonar.phpCodesniffer.reportFileName=myCodeSnifferReport.xml #default is codesniffer.xml #default is logs; parent is $PROJECT_HOME/.sonar/target when the analysis is triggered with the Sonar Runner, $PROJECT_HOME/target when triggered with Maven sonar.phpCodesniffer.reportFileRelativePath=<relative_path_from_parent_to_xml_report> #PHP Depend sonar.phpDepend.analyzeOnly=true sonar.phpDepend.reportFileName=myPhpDependReport.xml #default is pdepend.xml #default is logs; parent is $PROJECT_HOME/.sonar/target when the analysis is triggered with the Sonar Runner, $PROJECT_HOME/target when triggered with Maven sonar.phpDepend.reportFileRelativePath=<relative_path_from_parent_to_xml_report> sonar.phpDepend.reportType=summary-xml #Type of report generated by PHP Depend. Valid values: summary-xml, phpunit-xml (default value, deprecated) #PHPUnit sonar.phpUnit.analyzeOnly=true sonar.phpUnit.reportFileName=myPhpUnitReport.xml #default is phpunit.xml #default is logs; parent is $PROJECT_HOME/.sonar/target when the analysis is triggered with the Sonar Runner, $PROJECT_HOME/target when triggered with Maven sonar.phpUnit.reportFileRelativePath=<relative_path_from_parent_to_xml_report> sonar.phpUnit.coverage.analyzeOnly=true sonar.phpUnit.coverageReportFile=myCoverageReport.xml #default is phpunit.coverage.xml #Same path as sonar.phpUnit.reportFileRelativePath |
Note that the reports should be generated with the recommended version of each tool. Otherwise you may face some incompatibility issues. |
See Metrics documentation page.
See the tutorial to extend coding rules with PHP_CodeSniffer and/or PHPMD.