PHPMD

Web Sitehttps://phpmd.org/
LanguagePHP
Supported Version2.6.0

Getting Started

To start using PHPMD, enable it in repository setting.

To customize the analysis, configure using sideci.yml.

Using Your Configuration File

When you have own ruleset.xml for your project, you can use the file to setup rule set. Specify the path to rule option in sideci.yml.

linter:
  phpmd:
    options:
      rule: ruleset.xml

Performance Issue

PHPMD does not run fast, and sometimes analysis sessions times out.

To mitigate the difficulty, SideCI deletes files which is not changed in the pull request. This is automatically done (and you cannot disable that).

If it is still times out, you can limit the target of PHPMD analysis using sideci.yml.

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

The target option controls the PHPMD command line used in analysis.

Default Configuration

When you leave rule option undefined in sideci.yml, SideCI runs PHPMD with our recommended setting. The recommended setting is available in our GitHub repository.

Configuration via sideci.yml

Example settings for PHPMD under phpmd:

linter:
  phpmd:
    target:
      - index.php
      - wp-content
    options:
      rule: codesize,unusedcode
      minimumpriority: 3
      suffixes: php,phtml
      exclude: app/Vendor/
      strict: true

target

This option controls target files to inspect. You can select plural files. You need not declare it necessarily because this is the optional setting.
Write it as a list when you set this option.

options

This option controls command line options given to phpmd.

rule

This option controls --rule command line option given to phpmd. You can specify a comma separated rule names or an array of rule name.

The valid rule names are the following:

The value is passed to --rule command line option, and you can specify rule set file name.

linter:
  phpmd:
    options:
      rule: ruleset.xml

If you need detail of rules or how to customize ruleset, see PHPMD - PHP Mess Detector: Documentation#Rules.

minimumpriority

This option controls the rule priority threshold. The lower priority rules you declare will not be used.

suffixies

This option controls valid filename extensions. Write comma-separated in order to inspect plural extensions files. e.g. php,phtml

exclude

This option controls directories to exclude from analysis objects. Write comma-separated in order to inspect plural directories.
e.g. app/logs/,web/bundles/

strict

This option controls whether to report nodes with @SuppressWarnings annotation. Default value is false.
In order to know detail of @SuppressWarnings, see PHPMD Suppressing Warnings.