Skip to end of metadata
Go to start of metadata
You are viewing an old version of this page. View the current version. Compare with Current ·  View Page History
Live 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

The plugin enables analysis of PHP projects within Sonar.

It relies on well-known external tools: PHPUnit, PHP Depend, PHPMD and PHP_CodeSniffer.

Installation

  1. Install the PHP Environment
  2. Install the Sonar PHP plugin through the Update Center or download it into the SONAR_HOME/extensions/plugins directory
  3. Restart the Sonar server

Usage

Run a Sonar Analysis with the Sonar Runner (Recommended Way)

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.

Run a Sonar Analysis with the other Analyzers

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

Advanced Settings

Disabling or enabling external tools on demand

It is possible to disable each PHP tool.

 

Reusing existing reports

To reuse existing reports from PHP Depend, PHPUnit, etc.:

  1. Put these reports into $PROJECT_HOME/target/logs/.
  2. Set the property 'sonar.<external_tool>.analyzeOnly' to 'true'
  3. Set the 'sonar.<external_tool>.fileName' to the name of the report

 Also, you have to stick to the required version of tools supported from you version of Sonar PHP Plugin. Because sonar php plugin uses files located on the file system to make them match with violations, you have to be sure that your source directories and test directories are correctly referenced in your pom.xml even your project is not build with maven.

Here is an example:

FAQ and Troubleshooting

Extending Coding Rules

See the tutorial to extend coding rules with PHP_CodeSniffer and/or PHPMD.

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

Change Log

Release 1.1 (11 issues)
Type Key Summary Priority
Bug SONARPLUGINS-1972 Violation tracking can't work with PHPMD violations Critical
Task SONARPLUGINS-1988 Fix URL for update center Major
Task SONARPLUGINS-1964 Check compatibility with latests versions of PHPMD & PDepend Major
Bug SONARPLUGINS-1718 "sonar.*.argumentLine" properties are incorrectly passed to the external tool processes Major
Bug SONARPLUGINS-1711 PHP plugin not compatible with Java 7 Major
Bug SONARPLUGINS-1675 java launcher failed load php converage Major
Bug SONARPLUGINS-1657 PHP source importer not importing user defined suffixes Major
Bug SONARPLUGINS-1650 java.io.FileNotFoundException: Too many open files Major
Improvement SONARPLUGINS-1351 Use jdepend compatible report for storing metrics generated with PHP Depend Major
Bug SONARPLUGINS-1330 PHPDepend reports invalid jdepend.xml Major
Bug SONARPLUGINS-1643 Invalid eval expression rule name Trivial

 

Release 1.0 (14 issues)
Type Key Summary Priority
Bug SONARPLUGINS-1541 Coverage analysis crashes when "statements" metric is zero. Major
Bug SONARPLUGINS-1607 External tools should be launched at the root of the project that is analyzed Major
Bug SONARPLUGINS-1594 sonar.phpPmd.argumentLine argument not readable by phpmd Major
Bug SONARPLUGINS-1593 Argument sonar.phpCodesniffer.ignoreArgument not taken in account Major
Improvement SONARPLUGINS-1596 Remove the need of PHPCPD Major
Bug SONARPLUGINS-1591 PHP Coverage report parrsing can fail if a file has no statement Major
Bug SONARPLUGINS-1588 PHPUnit report parsing can lead to adding twice the same measure on a resource Major
Improvement SONARPLUGINS-1422 Improve error reporting when executing external tools Major
Bug SONARPLUGINS-1413 Importing an existing profile require priority to be present Major
Bug SONARPLUGINS-1354 Cannot analyse project with multiple test files Major
Bug SONARPLUGINS-1606 PHP Colorizer does not highlight reserved variables Major
Bug SONARPLUGINS-1601 All the "sonar.*.argumentLine" properties are incorrectly passed to the external tool processes Major
Task SONARPLUGINS-1598 Improve documentation on the Wiki Minor
Bug SONARPLUGINS-1590 PHPCS Rule not found at startup Minor

 

Release 0.6 (15 issues)
Type Key Summary Priority
Bug SONARPLUGINS-1508 PHP CodeSniffer does not use rule parameters that Sonar generates Critical
Improvement SONARPLUGINS-1421 "--extensions" PHPMD option is deprecated Major
Improvement SONARPLUGINS-1419 Create a "Sonar PHP Way" quality profile Major
Task SONARPLUGINS-1418 PHP CodeSniffer and PHP PMD rules cleanup Major
Bug SONARPLUGINS-1363 PHP Plugin poorly support ant build files Major
Improvement SONARPLUGINS-1440 Improve the way PHPUnit is executed from Sonar Major
Improvement SONARPLUGINS-1390 Make it possible to run PHP analyses with the Simple Java Runner Major
Bug SONARPLUGINS-1506 "sonar.phpcpd.excludes" can contain file separators that are currently not handled Major
Improvement SONARPLUGINS-1504 Improve PHPMD importer to find all rules related to a predefined ruleset Major
Improvement SONARPLUGINS-1503 Improve PHP CodeSniffer importer to find all rules related to a sniff Major
Bug SONARPLUGINS-1499 PHP CodeSniffer importer does not correctly set severities on imported rules Major
Improvement SONARPLUGINS-1501 Upgrade to PHP CodeSniffer 1.3.1 Major
Bug SONARPLUGINS-1498 PHP CodeSniffer exporter does not correctly generate rule severities Major
Bug SONARPLUGINS-1367 sonar launch PHPUnit without working directory Major
Improvement SONARPLUGINS-1073 Add properties for existing php codesniffer and phpmd rules Major

 

Release 0.5 (23 issues)
Type Key Summary Priority
Bug SONARPLUGINS-1420 Unable to parse phpmd result file when workspace path contains spaces Major
Bug SONARPLUGINS-1416 PHP CPD exclude parameter does not work Major
Improvement SONARPLUGINS-1415 Make PHP plugin compatible with SCM plugin Major
Bug SONARPLUGINS-1400 Some PHP CodeSniffer rules do not exist in v1.3.0 Major
Improvement SONARPLUGINS-1399 Clean and standardize configuration parameters Major
Task SONARPLUGINS-1398 Update installation process documentation Major
Sub-task SONARPLUGINS-1396 Regression of fine-tuning of names and location of logs Major
Improvement SONARPLUGINS-1394 Set coverage to 0 for files that are not reported by PhpUnit Major
Task SONARPLUGINS-1391 Refactor the way PHP plugin handles resources Major
Bug SONARPLUGINS-1256 The option sonar.dynamicAnalysis=reuseReports with Php plugin 0.4 installed doesn't work on a java project Major
Bug SONARPLUGINS-1255 Typo Error Trivial
Bug SONARPLUGINS-1253 PHP Plugins doesn't show CodeSniffer violations Major
Bug SONARPLUGINS-1180 PHP Sonar plulgin 0.4 is not compatible with Sonar 2.8 (Source code is not available) Critical
Improvement SONARPLUGINS-1170 PDepend: CLASSES Measure Fix, new DEPTH_IN_TREE, NUMBER_OF_CHILDREN Measures Minor
Bug SONARPLUGINS-1169 PhpUnit treats dynamicAnalysis option as a boolean Major
Improvement SONARPLUGINS-1109 Import of Violations is too slow for large projects Major
Bug SONARPLUGINS-1093 Multiple exclude directories for phpcpd do not work. Major
Improvement SONARPLUGINS-1064 Update to PHPMD 1.1.0 Major
Sub-task SONARPLUGINS-1058 Replace sonar.phpPmd.shouldRun with sonar.phpPmd.skip Major
Sub-task SONARPLUGINS-1057 Replace sonar.phpUnit.shouldRun with sonar.phpUnit.skip Major
Sub-task SONARPLUGINS-1056 Replace sonar.phpDepend.shouldRun with sonar.phpDepend.skip Major
Sub-task SONARPLUGINS-1055 Replace sonar.phpCodesniffer.shouldRun with sonar.phpCodesniffer.skip Major
Sub-task SONARPLUGINS-1029 Change sonar.php.cpd.skip option into sonar.phpcpd.skip Major

 

Release 0.4 (15 issues)
Type Key Summary Priority
Bug SONARPLUGINS-975 phpcpd always running Major
Bug SONARPLUGINS-974 Settings for exclude directorys and files not honored Blocker
Bug SONARPLUGINS-961 Settings for suffixes not working (File suffixes [sonar.php.file.suffixes]) Major
Bug SONARPLUGINS-946 Destination directory for report analysis file is not created if not present Major
Improvement SONARPLUGINS-945 Be able to change the properties of rules Major
Bug SONARPLUGINS-944 Don't display verbose logs Critical
Bug SONARPLUGINS-924 PHP Plugin doesn't recognise reuseReports as a valid option for sonar.dynamicAnalysis Critical
Bug SONARPLUGINS-918 phpunit command generation depends on maven project name Major
Bug SONARPLUGINS-917 Sonar Phpunit properties dependency Major
Bug SONARPLUGINS-916 Cannot analyse project with multiple test files Major
Bug SONARPLUGINS-909 excludetests test parameter incorrectly passed to phpcpd (missing space) Major
Bug SONARPLUGINS-889 sonar.phpcpd.excludes generates invalid phpcpd command line (missing space) Major
Improvement SONARPLUGINS-806 Ignore disabled rules during the analysis Major
Improvement SONARPLUGINS-750 Update the plugin site with a simple "How To Use" section. Major
New Feature SONARPLUGINS-748 Support test-directory based PHPUnit tests when 'AllTests.php' is not defined. Major

 

Release 0.3 (23 issues)
Type Key Summary Priority
Improvement SONARPLUGINS-862 Make the plugin compatible with Sonar 2.3 Major
Bug SONARPLUGINS-805 Add a rule repository containing all PHP rules (phpcodesniffer rules and pmd rules) Critical
Improvement SONARPLUGINS-777 Manage PHP source code exclusion Major
New Feature SONARPLUGINS-758 Support of "NOSONAR" comments Major
Sub-task SONARPLUGINS-686 Update wiki documentation to explain phpcpd installation Major
Task SONARPLUGINS-676 Update Sonar PHP Plugin documentation to match the fact that the plugin is now one jar to deploy Major
Improvement SONARPLUGINS-617 Replace SQLI_CodeSniffer with PHP_CodeSniffer 1.3 Critical
Improvement SONARPLUGINS-616 Replace Java CPD with phpcpd Critical
Bug SONARPLUGINS-604 rules.xml encoding Major
Bug SONARPLUGINS-589 Sonar 2.1.1 error: This measure has already been saved Major
Bug SONARPLUGINS-578 Make the plugin compatible with Sonar 2.2 Major
Improvement SONARPLUGINS-571 PHP projects report no coverage when grouped with the Views plugin. Major
Bug SONARPLUGINS-566 Duplicate measure when project has two files that differ only by suffix Critical
Wish SONARPLUGINS-565 Add a way to specify supported file suffixes Critical
Bug SONARPLUGINS-547 PhpDependExecutor: wrong dirs params Major
Bug SONARPLUGINS-546 PhpPmdExecutor: wrong dirs params Major
Bug SONARPLUGINS-520 PhpCodeSniffer violations are not taken into account in Sonar Major
Improvement SONARPLUGINS-512 Ease the plugin installation by providing a single jar Major
Improvement SONARPLUGINS-510 The use of "-Dsonar.dynamicAnalysis=false" standard parameter should deactivate the execution of PHP_Unit Minor
Improvement SONARPLUGINS-509 By default, all violation messages should be in english and not in french Major
Improvement SONARPLUGINS-507 Activate syntax highlighting on PHP source code Minor
Improvement SONARPLUGINS-218 CPD should not count comments as duplicated tokens Major
Improvement SONARPLUGINS-217 Enable multiple source directories Major

 

Release 0.2 (9 issues)
Type Key Summary Priority
Improvement SONARPLUGINS-519 Add simple php project to SVN for testing Minor
Bug SONARPLUGINS-518 sonar-php-depend failed Major
Bug SONARPLUGINS-517 Warning "Trying to save twice the source of" Major
Bug SONARPLUGINS-516 "sonar.phpPmd.shouldRun=false" doesn't work Major
Bug SONARPLUGINS-514 PDepend analyze fails Blocker
Bug SONARPLUGINS-513 Empty packages appear after analysis of project Major
Bug SONARPLUGINS-511 Duration of unit test seems to be wrong Major
Improvement SONARPLUGINS-219 Get complexity distribution to work Major
New Feature SONARPLUGINS-31 Scan PHP projects Major

Labels
  • None