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
Sonar PHP Plugin provides PHP language support to Sonar. The plugin enables all Sonar builtin features for analysis of PHP projects with SonarQube.
It relies on well known external analysis tools for PHP: PHP Unit, PHP Depend, PHPMD and PHP_CodeSniffer.
Sonar PHP Plugin
The versions listed above are those we use for developments and tests, and we recommend you to also install those ones (even if the PHP Plugin might be compatible with older versions as well).
Where to start?
Here are the main steps to get started:
- Install Sonar and its requirements, plus the PHP plugin and everything that is needed to run analyses
- Then, choose how you want to run an analysis on your PHP project, and enjoy the results!
Once you're familiar with the plugin, you can dig more into the documentation to discover advanced features (like adding your own PHP CodeSniffer or PHPMD rules into Sonar).
Have some questions or problems?
Here's the path you should follow in this case:
- First check the plugin's FAQ or Troubleshooting sections.
- See if there is any open issues that may be linked to your question/problem
- Eventually send a mail on the user mailing list (email@example.com) to ask for help
- 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
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
Unit Tests and Code Coverage
To display unit test execution and code coverage data:
- Prior to the SonarQube analysis, execute your unit tests and generate PHPUnit (execution + code coverage) XML reports.
- Import these reports while running the SonarQube analysis by setting the:
sonar.php.coverage.reportPathproperty to the path to the PHPUnit code coverage report file. The path may be either absolute or relative to the project base directory.
sonar.php.tests.reportPathproperty to the path to the PHPUnit unit test execution report file. The path may be either absolute or relative to the project base directory.
The PHP plugin does not rely anymore on external tools.