Skip to content
PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.
Branch: master
Clone or download

Latest commit

kylekatarnls Merge pull request #789 from TJVB/update_coding_standard_description_…

Update CONTRIBUTING to point out to the correct coding standard
Latest commit 9aad520 May 21, 2020


Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Fixed typos Apr 15, 2020
setup @ 754fd29 Make Scrutinizer happy :) Jan 20, 2017
src Improve wording May 19, 2020
.editorconfig Add *.json to .editorconfig Jun 11, 2017
.gitattributes Add .github to the .gitattributes file to prevent it from being downl… Jul 29, 2019
.gitignore Ignoring any XML files in the root Apr 21, 2020
.gitmodules Use composer for the dependencies. Dec 14, 2012
.mailmap Add .mailmap file to fix git shortlog Nov 24, 2016
.scrutinizer.yml Use scrutinizer default tests settings Dec 22, 2019
.stickler.yml Let Stickler CI use our new PHPCS CS definition Apr 21, 2020
.travis.yml Fix #717 Restore RST files on Dec 31, 2019
AUTHORS.rst Move myself to the maintainers Jun 6, 2017
CHANGELOG Add the release date for 2.8.2 (#736) Feb 25, 2020 Update CONTRIBUTING to point out to the correct coding standard May 20, 2020
LICENSE Change year to initial release year Jun 25, 2019
README.rst exclude pattern documentation Apr 5, 2020
apigen.neon Add ApiGen config file Mar 24, 2017
appveyor.yml Disable Windows update service Jul 12, 2019 Add important note May 6, 2020
build.xml Bump to minimal version 5.3.9 Aug 17, 2019
composer.json Remove files to check with PHPCS as they are not configured Apr 22, 2020
pdepend.xml.dist PDepend file added. Mar 2, 2015
phpcs.xml.dist Add files to check wih PHPCS to its configuration Apr 22, 2020
phpunit.xml.dist Refactor - removed right side spaces Oct 21, 2014



PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

Latest Stable Version License Travis Build Status AppVeyor Build Status Scrutinizer Build Status Scrutinizer Code Quality Chat with us on Gitter Monthly downloads Total downloads



Command line usage

Type phpmd [filename|directory] [report format] [ruleset file], i.e:

mapi@arwen ~ $ phpmd php/PDepend/DbusUI/ xml rulesets.xml

While the rulesets.xml ruleset file could look like this:

<?xml version="1.0"?>
<ruleset name="My first PHPMD rule set"
    My custom rule set that checks my code...

  <rule ref="rulesets/codesize.xml" />
  <rule ref="rulesets/cleancode.xml" />
  <rule ref="rulesets/controversial.xml" />
  <rule ref="rulesets/design.xml" />
  <rule ref="rulesets/naming.xml" />
  <rule ref="rulesets/unusedcode.xml" />

The xml report would like like this:

<?xml version="1.0" encoding="UTF-8" ?>
<pmd version="0.0.1" timestamp="2009-12-19T22:17:18+01:00">
  <file name="/projects/pdepend/PHP/Depend/DbusUI/ResultPrinter.php">
    <violation beginline="81"
               ruleset="Unused Code Rules"
      Avoid unused parameters such as '$builder'.

You can pass a file name or a directory name containing PHP source code to PHPMD.

The PHPMD Phar distribution includes the rule set files inside its archive, even if the "rulesets/codesize.xml" parameter above looks like a filesystem reference.

Command line options

  • Notice that the default output is in XML, so you can redirect it to a file and XSLT it or whatever

  • You can also use shortened names to refer to the built-in rule sets, like this:

    phpmd PHP/Depend/DbusUI/ xml codesize
  • The command line interface also accepts the following optional arguments:

    • --minimumpriority - The rule priority threshold; rules with lower priority than they will not be used.
    • --reportfile - Sends the report output to the specified file, instead of the default output target STDOUT.
    • --suffixes - Comma-separated string of valid source code filename extensions, e.g. php,phtml.
    • --exclude - Comma-separated string of patterns that are used to ignore directories. Use asterisks to exclude by pattern. For example *src/foo/*.php or *src/foo/*
    • --strict - Also report those nodes with a @SuppressWarnings annotation.
    • --ignore-violations-on-exit - will exit with a zero code, even if any violations are found.

    An example command line:

    phpmd PHP/Depend/DbusUI xml codesize --reportfile phpmd.xml --suffixes php,phtml

Using multiple rule sets

PHPMD uses so called rule sets that configure/define a set of rules which will be applied against the source under test. The default distribution of PHPMD is already shipped with a few default sets, that can be used out-of-box. You can call PHPMD's cli tool with a set's name to apply this configuration:

~ $ phpmd /path/to/source text codesize

But what if you would like to apply more than one rule set against your source? You can also pass a list of rule set names, separated by comma to PHPMD's cli tool:

~ $ phpmd /path/to/source text codesize,unusedcode,naming

You can also mix custom rule set files with build-in rule sets:

~ $ phpmd /path/to/source text codesize,/my/rules.xml

That's it. With this behavior you can specify you own combination of rule sets that will check the source code.

Using multiple source files and folders

PHPMD also allowes you to specify multiple source directories in case you want to create one output for certain parts of your code

~ $ phpmd /path/to/code,index.php,/another/place/with/code text codesize

Exit codes

PHPMD's command line tool currently defines three different exit codes.

  • 0, This exit code indicates that everything worked as expected. This means there was no error/exception and PHPMD hasn't detected any rule violation in the code under test.
  • 1, This exit code indicates that an error/exception occured which has interrupted PHPMD during execution.
  • 2, This exit code means that PHPMD has processed the code under test without the occurence of an error/exception, but it has detected rule violations in the analyzed source code. You can also prevent this behaviour with the --ignore-violations-on-exit flag, which will result to a 0 even if any violations are found.


At the moment PHPMD comes with the following renderers:

  • xml, which formats the report as XML.
  • text, simple textual format.
  • html, single HTML file with possible problems.
  • json, formats JSON report.
  • ansi, a command line friendly format.

PHPMD for enterprise

Available as part of the Tidelift Subscription.

The maintainers of PHPMD and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

You can’t perform that action at this time.