Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Update xml format name for coverage
Wiki Markup
{iframe:src=http://update.sonarsource.org/plugins/php-confluence.html|width=700|height=250350|frameborder=0}
Your browser does not support iframes.
{iframe}
Tip
titleLive 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

Sonar PHP Plugin provides PHP language support to Sonar. The plugin enables all Sonar builtin features for PHP projects.

It relies on well known external analysis tools for PHP: PHP Unit, PHP Depend, PHPMD and PHP_CodeSniffer.

Sonar PHP Plugin

PHP Runtime

PHPUnit

PHP Depend

PHPMD

PHP_CodeSniffer

PhpCPD

0.3

5.2.6+

3.5.5

0.9.14

0.2.5

1.3.0RC1

1.3.1

0.4

5.2.6+

3.5.5

0.9.14

0.2.5

1.3.0RC1

1.3.1

0.5

5.2.6+

3.5.5

0.10.6

1.1.0

1.3.0RC1

1.3.1

0.6

5.2.6+

3.5.5

0.10.6

1.1.0

1.3.1

1.3.1
1.05.2.6+3.5.50.10.71.2.01.3.2-
1.15.2.6+3.5.51.0.31.3.21.3.2-
Info
titleWhich versions of the external tools should you use?

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:

  1. Install Sonar and its requirements, plus the PHP plugin and everything that is needed to run analyses
  2. 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:

  1. First check the plugin's FAQ or Troubleshooting sections.
  2. See if there is any open issues that may be linked to your question/problem
  3. Eventually send a mail on the user mailing list (user@sonar.codehaus.org) to ask for help

Roadmap

  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

Changelog

JIRA Issues
anonymoustrue
titleRelease 1.1
height110
width900
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+SONARPLUGINS+AND+fixVersion+%3D+"PHP-1.1"+AND+component+%3D+PHP+AND+status+%3D+Closed+ORDER+BY+priority+DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleRelease 1.0
height110
width900
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+SONARPLUGINS+AND+fixVersion+%3D+"PHP-1.0"+AND+component+%3D+PHP+AND+status+%3D+Closed+ORDER+BY+priority+DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleRelease 0.6
height110
width900
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?jqlQuery=project+%3D+SONARPLUGINS+AND+fixVersion+%3D+17853+AND+component+%3D+PHP+AND+status+%3D+Closed+ORDER+BY+priority+DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleRelease 0.5
height110
width900
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=17298&pid=11911&sorter/field=issuekey&sorter/order=DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleRelease 0.4
height110
width900
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=16696&pid=11911&sorter/field=issuekey&sorter/order=DESC&tempMax=1000

 

JIRA Issues
anonymoustrue
titleRelease 0.3
height110
width900
columnstype;key;summary;priority;status;resolution
urlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=16522&pid=11911&sorter/field=issuekey&sorter/order=DESC&tempMax=1000

 

JIRA IssuesanonymoustruetitleRelease 0.2height110width900columnstype;key;summary;priority;status;resolutionurlhttp://jira.codehaus.org/sr/jira.issueviews:searchrequest-xml/temp/SearchRequest.xml?fixfor=16432&pid=11911&sorter/field=issuekey&sorter/order=DESC&tempMax=1000analysis of PHP source code with SonarQube. Pure PHP files and mixed HTML / PHP files can be analyzed.

Since version 2.1

You can check compliance with PHP coding standards:

  • PSR-2: the quality profile of this name contains the rules to be PSR-2 compliant.

 

Info
titleSince version 2.0

Dependency on external tools has been removed: i.e PHPDepend, PHPCodeSniffer, PHPMD, PHPUnit.

It means that the plugin relies only on the SonarQube rule engine; there is no import of external rule engine results. (PHPUnit reports can still be imported.)

Many PHPMD rules are now offered natively by the plugin. If you think that the plugin is missing some "must have" rules, you are very welcome to send your suggestions to user@sonar.codehaus.org.

Include Page
Include - Plugin Installation
Include - Plugin Installation

Usage

Run an Analysis with the SonarQube Runner (Recommended method)

To run an analysis of your PHP project, use the SonarQube Runner.

A sample project is available on GitHub that can be browsed or downloaded/projects/languages/php/php-sonar-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

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

Unit Tests and Code Coverage

To display unit test execution and code coverage data:

  1. Prior to the SonarQube analysis, execute your unit tests and generate a report in Clover XML format (execution + code coverage).
  2. Import these reports while running the SonarQube analysis by setting the:
    •  sonar.php.coverage.reportPath property 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.reportPath property to the path to the PHPUnit unit test execution report file. The path may be either absolute or relative to the project base directory.

A sample project is available on GitHub that can be browsed or downloaded/projects/languages/php/php-sonar-runner-unit-tests.

Metrics

See Metrics documentation page.

Release Notes

Version 2.0

The PHP plugin does not rely anymore on external tools.