- General questions
- I have projects that do not use the required version of phpunit or pdepend or phpcd or whatelse, what can I do?
- I have created my own PHP_CodeSniffer Standard or PHPMD ruleset, can I use it with Sonar PHP ?
- File exclusions
- How do I exclude files from a Sonar analysis?
- How do I prevent external tools from analysing some source files?
- Unit tests / PhpUnit integration questions
I have projects that do not use the required version of phpunit or pdepend or phpcd or whatelse, what can I do?
If you are able to have several versions of code analysis tool on the same machine, just be sure that the correct one will be used by maven when launching mvn sonar:sonar.
You also have to ensure that the output file log is compatible with the one specified by the version of the tool you want to use.
I have created my own PHP_CodeSniffer Standard or PHPMD ruleset, can I use it with Sonar PHP ?
Yes, but with some extra work. Two possible cases :
1) Your work consisted in pure configuration: modify a ruleset for PHPMD or create a PHPCS Standard including Sniffs from existing standards.
In this case you'll be able to recreate your work directly from the Sonar UI for Quality Profiles
NB As per this version (0.6) you must check for the presence of your rules in Sonar profiles, as some PHPCS rule description is still missing.
If you don't find all of your rules, you simply fall in case 2.
2) You added code to the solutions: you developed Sniffs or PHP PMD Rules
In this case you will have to Extend the PHP coding rules
How do I exclude files from a Sonar analysis?
To exclude files from the PHP analysis, just use the standard "sonar.exclusions" property. For example, in a "sonar-project.properties" file, this would look like:
This pattern means: any PHP file located in a source folder which path contains the "Database" folder.
- "**/Database/*.php" would mean: any PHP file directly located in a "Database" folder
- "Database/**/*.php" would mean: any PHP file located in a source folder that starts with a "Database" folder
Please note that the exclusion patterns are relative to the source folder.
How do I prevent external tools from analysing some source files?
Most of the time, using the "sonar.exclusions" property (as explained in the previous question) will be enough to exclude files from being reported by Sonar. However, there might be some cases where one really wants to exclude files from being analysed by an external tool (may it be PHP CodeSniffer, PHPMD or PDepend):
- a file is badly written and the tool is crashing when analysing this file, thus preventing Sonar from completing the analysis
- a big number of file must be excluded and there's no need for the external tools to spend time analysing files that won't be reported by Sonar
In those specific cases, you should use the "sonar.xxxx.argumentLine" property of the external tools to manually add the exclusions you want. For instance, for PHP CodeSniffer, you would add the following property (example given for a "sonar-project.properties" file):
This would tell PHP CodeSniffer to ignore every PHP file located in the "Database" folder.
When specifying exclusions directly for each tool, you should also consider specifying the "sonar.exclusions" accordingly. Otherwise, you may have files with incomplete analyses.
Unit tests / PhpUnit integration questions
How do I disable unit test & coverage reporting?
The easiest way to disable unit test reporting is to use the following standard Sonar property (example given for a "sonar-project.properties" file):
If you want to disable only unit test reporting or coverage reporting, you can use the following properties instead: