Skip to main content

PHPMD

Supported VersionLanguageWebsite
2.10.1PHPhttps://phpmd.org

PHPMD is a static analysis tool focused on detecting code smells and possible errors in your PHP code.

Getting Started#

To start using PHPMD, enable it in your repository settings.

Default Configuration for PHPMD#

Sider provides our recommended ruleset for PHPMD. This configuration is used when the rule option is not specified in sider.yml in your repository. For more details, please visit Recommended Ruleset.

Performance Issues#

PHPMD sometimes raises analysis timeout with a larger codebase.

To mitigate this, Sider deletes files that are not changed in the pull request. This behavior is automatically done and cannot be disabled.

If PHPMD still raises timeout, you can reduce target files of PHPMD analysis by using the target option:

linter:  phpmd:    target:      - index.php      - wp-content/

Configuration#

Here is an example configuration via sider.yml:

linter:  phpmd:    target:      - index.php      - wp-content/    rule:      - codesize      - unusedcode      - my_custom_ruleset.xml    minimumpriority: 3    suffixes: [php, phtml]    exclude:      - app/vendor/      - "test/*.php"    strict: true    custom_rule_path:      - Custom_PHPMD_Rule.php      - "custom/phpmd/rules/**/*.php"

You can use several options to fine-tune PHPMD to your project:

NameTypeDefault
root_dirstring-
targetstring, string[].
rulestring, string[](see below)
minimumpriorityinteger-
suffixesstring, string[]php
excludestring, string[]-
strictbooleanfalse
custom_rule_pathstring[][]

See also the PHPMD document for details.

target#

This option allows you to specify files or directories to analyze.

rule#

This option allows you to specify the predefined ruleset names or your custom ruleset file paths. The value can be a comma-separated list.

Here are the available rulesets:

  • cleancode
  • codesize
  • controversial
  • design
  • naming
  • unusedcode

If omitted, Sider uses the recommended ruleset.

If you want to learn more, see the PHPMD ruleset document.

minimumpriority#

This option allows you to specify the rule priority threshold. Rules with lower priority than the specified value will not be reported.

suffixes#

This option allows you to specify file extensions to analyze. Use a comma-separated list for multiple values, e.g. php,phtml.

exclude#

This option allows you to specify directories to exclude from analysis objects. You can use asterisk patterns and use a comma-separated list for multiple values, e.g. src/foo/*.php,*src/foo/*.

strict#

This option allows you to specify whether reports nodes that have the @SuppressWarnings annotation or not.

custom_rule_path#

This option allows you to specify your own custom rule PHP file paths. Glob pattern is also available. You need to use it along with the rule option. For example:

# sider.ymllinter:  phpmd:    rule: custom_ruleset.xml    custom_rule_path:      - Custom_PHPMD_Rule.php      - "custom/phpmd/rules/**/*.php"
<!-- custom_ruleset.xml --><?xml version="1.0" encoding="utf-8"?><ruleset name="Your Custom Ruleset">  <rule name="SomeYourCustomRule"        message="Please do not this."        class="Custom_PHPMD_Rule"        externalInfoUrl="https://example.com/phpmd/rules/custom-rule">    <priority>1</priority>  </rule></ruleset>