PHP Mess Detector
Language / Framework:PHP
Categories: Clarity, Style, Bug Risk, Compatibility
PHPMD Version: 2.10.3
PHPMD looks for several potential problems within PHP source code, like possible bugs, suboptimal code, overcomplicated expressions, and unused parameters, methods, or properties.
Enable the Plugin
To enable PHPMD analysis, add the following to your
.codeclimate.yml configuration file:
plugins: phpmd: enabled: true
More information about the CLI is available in the README here: https://github.com/codeclimate/codeclimate
Configure the Plugin
You can specify which file extensions you'd like our PHPMD engine to analyze by adding a
file_extensions key nested under an engine
config key in your .codeclimate.yml:
plugins: phpmd: enabled: true config: file_extensions: - php - inc
PHP Mess Detector offers a variety of checks for your PHP code, including:
You can configure our PHPMD engine to use the rulesets most valuable to your team, and also provide paths to custom rulesets:
plugins: phpmd: enabled: true config: file_extensions: "php" rulesets: "unusedcode,codesize,naming,optional_relative_path_to_custom_ruleset.xml"
If no rulesets are specified in your .codeclimate.yml, our PHPMD engine by default includes checks from all six of the above rulesets.
Standard PHPMD checks come set up with certain thresholds by default. To adjust these, add a custom ruleset that includes the PHPMD ruleset of interest, and excludes the rules for which you'd like to set custom values. Add these rules in the same
.xml ruleset file separately.
For instance, to set the
TooManyPublicMethods to 25, add a custom ruleset.xml that includes the
codesize ruleset excluding that rule, then lists the
TooManyPublicMethods rule separately with the desired value.
<?xml version="1.0"?> <ruleset name="PHPMD rule set for my project" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> <description>Custom rules for checking my project</description> <rule ref="rulesets/codesize.xml"> <exclude name="TooManyPublicMethods"/> </rule> <rule ref="rulesets/codesize.xml/TooManyPublicMethods"> <properties> <property name="maxmethods" value="25" /> </properties> </rule> </ruleset>
.codeclimate.yml config under the phpmd engine rulesets, include the path to this custom ruleset file only, and omit the
codesize ruleset. This step is important because PHPMD rulesets are additive.
plugins: phpmd: enabled: true config: file_extensions: - php - inc rulesets: "unusedcode,naming,myRuleset.xml"
Understand the Plugin
For more information about all the checks available and their configuration options, please check out the documentation here: https://phpmd.org
Updated over 1 year ago