PHPackages                             phpmd/phpmd - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. phpmd/phpmd

ActiveLibrary[Testing &amp; Quality](/categories/testing)

phpmd/phpmd
===========

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD.

2.15.0(2y ago)2.4k108.5M—2.5%350[71 issues](https://github.com/phpmd/phpmd/issues)[9 PRs](https://github.com/phpmd/phpmd/pulls)20BSD-3-ClausePHPPHP &gt;=5.3.9CI passing

Since Sep 7Pushed today49 watchersCompare

[ Source](https://github.com/phpmd/phpmd)[ Packagist](https://packagist.org/packages/phpmd/phpmd)[ Docs](https://phpmd.org/)[ Fund](https://tidelift.com/funding/github/packagist/phpmd/phpmd)[ RSS](/packages/phpmd-phpmd/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (63)Used By (20)

PHPMD
=====

[](#phpmd)

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](https://camo.githubusercontent.com/70fc0da94c1e4f8bf9de6000228a12ea06ce486509fa010b86d92c0eba75f207/68747470733a2f2f706f7365722e707567782e6f72672f7068706d642f7068706d642f762f737461626c652e737667)](https://packagist.org/packages/phpmd/phpmd)[![License](https://camo.githubusercontent.com/6fab692797cff71b66494c4daf050442186b16fb4c06b0bef8028759f63340da/68747470733a2f2f706f7365722e707567782e6f72672f7068706d642f7068706d642f6c6963656e73652e737667)](https://packagist.org/packages/phpmd/phpmd)[![AppVeyor Build Status](https://camo.githubusercontent.com/ebfca02d6bcd8a4350dd87abd20a5a74390f591ce026dda33aa02f7f559f7024/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f706330386f7762756e327930306b776b3f7376673d74727565)](https://ci.appveyor.com/project/phpmd/phpmd)[![Codecov Status](https://camo.githubusercontent.com/ecb1dfec67704cd2a4d5792754bb02cbdf55fb6fe6142931dd284bae56cb01e8/68747470733a2f2f636f6465636f762e696f2f67682f7068706d642f7068706d642f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d5872427276544c4a6545)](https://codecov.io/gh/phpmd/phpmd)[![Scrutinizer Build Status](https://camo.githubusercontent.com/22e55c3e66316f76d1e025fe453cc1878649b33838c9cb7dd4989054d86bd559/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706d642f7068706d642f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpmd/phpmd/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8b7c02e0fd3e868f08472acd3aae2bbcfe386c3a808c9ed5cbb3ed6044e99b7b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068706d642f7068706d642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/phpmd/phpmd/?branch=master)[![Chat with us on Gitter](https://camo.githubusercontent.com/f785ed538c3ec33832fd574099947526f5805da7a3e1c1da66b126fcf23faafa/68747470733a2f2f6261646765732e6769747465722e696d2f7068706d642f636f6d6d756e6974792e737667)](https://gitter.im/phpmd/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)[![Monthly downloads](https://camo.githubusercontent.com/26f0f8a74f7725ff47dadca879709223f87edb2fa0847adb888ef31695386299/68747470733a2f2f706f7365722e707567782e6f72672f7068706d642f7068706d642f642f6d6f6e74686c79)](https://packagist.org/packages/phpmd/phpmd)[![Total downloads](https://camo.githubusercontent.com/71d5ab37bbef1c5771b73f080196c837613037b6ba8f2d6dd687b3ab1ab753d7/68747470733a2f2f706f7365722e707567782e6f72672f7068706d642f7068706d642f646f776e6c6f616473)](https://packagist.org/packages/phpmd/phpmd)Installation
------------

[](#installation)

See

Command line usage
------------------

[](#command-line-usage)

Type `phpmd [filename|directory[,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:

```

    My custom rule set that checks my code...

```

The xml report would like like this:

```

      Avoid unused parameters such as '$builder'.

```

You can pass a comma-separated string with list of file names or a directory names, containing PHP source code to PHPMD.

The [PHPMD Phar distribution](https://phpmd.org/download/index.html) includes the rule set files inside its archive, even if the "rulesets/codesize.xml" parameter above looks like a filesystem reference.

Command line options
--------------------

[](#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:

    - `--verbose, -v, -vv, -vvv` - The output verbosity level. Will print more information what is being processed or cached. Will be send to `STDERR` to not interfere with report output. `text` output will also have under each error a link to the documentation of the rule and format the location in a way that most IDEs will convert into a link to open the file at the line of the error when clicked.
    - `--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-errors-on-exit` - will exit with a zero code, even on error.
    - `--ignore-violations-on-exit` - will exit with a zero code, even if any violations are found.
    - `--cache` - will enable the result cache. Will default to `.phpmd.result-cache.php` in the current working directory.
    - `--cache-file` - in cooperation with `--cache` will override the default result cache file path of `.phpmd.result-cache.php` to the given file path.
    - `--cache-strategy` - sets the caching strategy to determine if a file is still fresh. Either content to base it on the file contents, or timestamp to base it on the file modified timestamp.
    - `--generate-baseline` - will generate a `phpmd.baseline.xml` for existing violations next to the ruleset definition file. The file paths of the violations will be relative to the current working directory.
    - `--update-baseline` - will remove all violations from an existing `phpmd.baseline.xml`that no longer exist. New violations will \_not\_ be added. The file path of the violations will be relative to the current working directory.
    - `--baseline-file` - the filepath to a custom baseline xml file. If absent will default to `phpmd.baseline.xml`
    - `--color` - enable color in output, for instance text renderer will show rule name in yellow and error description in red.
    - `--extra-line-in-excerpt` - specify how many extra lines are added to a code snippet in html format

    An example command line:

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

    Options can be before or after arguments. They can be separated from their value either with a space or an equal (`=`) sign. Thus, the following syntax is equivalent to the previous one:

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

    Strings starting with `-` will be recognized as option names. If you have arguments starting with `-`, set options first, then use `--` to mark the explicit start or the arguments list:

    ```
    phpmd --reportfile "phpmd.xml" --suffixes "php,phtml" -- -foo/Folder xml codesize
    ```

### Using multiple rule sets

[](#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](https://phpmd.org/documentation/creating-a-ruleset.html) with built-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

[](#using-multiple-source-files-and-folders)

PHPMD also allows 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
```

Or use glob pattern:

```
~ $ phpmd src/main/php/*/*/*{Renderer,Node}.php text my/rules.xml
```

### Scan input

[](#scan-input)

PHPMD can also read the standard input stdin:

```
~ $ cat src/MyService.php | phpmd - text my/rules.xml
```

So the PHP code to be scanned may be generated by an other program not necessarily to be store in file.

Exit codes
----------

[](#exit-codes)

PHPMD's command line tool currently defines four 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 exception occurred which has interrupted PHPMD during execution.
- *2*, This exit code means that PHPMD has processed the code under test without the occurrence 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 0even if any violations are found.
- *3*, This exit code means that one or multiple files under test could notbe processed because of an error. There may also be violations in other files that could be processed correctly.

Renderers
---------

[](#renderers)

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.
- *github*, a format that GitHub Actions understands.
- *gitlab*, a format that GitLab CI understands.
- *sarif*, the Static Analysis Results Interchange Format.
- *checkstyle*, language and tool agnostic XML format

Baseline
--------

[](#baseline)

For existing projects a violation baseline can be generated. All violations in this baseline will be ignored in further inspections.

The recommended approach would be a `phpmd.xml` in the root of the project. To generate the `phpmd.baseline.xml` next to it:

```
~ $ phpmd /path/to/source text phpmd.xml --generate-baseline
```

To specify a custom baseline filepath for export:

```
~ $ phpmd /path/to/source text phpmd.xml --generate-baseline --baseline-file /path/to/source/phpmd.baseline.xml
```

By default PHPMD will look next to `phpmd.xml` for `phpmd.baseline.xml`. To overwrite this behaviour:

```
~ $ phpmd /path/to/source text phpmd.xml --baseline-file /path/to/source/phpmd.baseline.xml
```

To clean up an existing baseline file and *only remove* no longer existing violations:

```
~ $ phpmd /path/to/source text phpmd.xml --update-baseline
```

PHPMD for enterprise
--------------------

[](#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.](https://tidelift.com/subscription/pkg/packagist-phpmd-phpmd?utm_source=packagist-phpmd-phpmd&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)

Contributing
------------

[](#contributing)

If you want to contribute to PHPMD, please consult the [contribution guide](./.github/CONTRIBUTING.md).

###  Health Score

72

—

ExcellentBetter than 100% of packages

Maintenance64

Regular maintenance activity

Popularity80

Widely adopted with strong download metrics

Community68

Healthy contributor diversity

Maturity72

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~104 days

Recently: every ~313 days

Total

48

Last Release

92d ago

Major Versions

1.5.0 → 2.0.0-beta.12014-03-13

1.5.1 → 2.1.22014-09-25

2.15.0 → 3.x-dev2026-02-15

PHP version history (3 changes)1.4.0PHP &gt;=5.3.0

2.4.4PHP &gt;=5.3.9

3.x-devPHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/b319e683a7001c095bcf138d870d7b7ed12a1040e11c0264b914c2e213922169?d=identicon)[ravage84](/maintainers/ravage84)

![](https://www.gravatar.com/avatar/df90c422f521bf26355c3e185a59fe7afb35531af56244dfaec03ee1d0ca6f24?d=identicon)[kylekatarn](/maintainers/kylekatarn)

![](https://www.gravatar.com/avatar/3fbe657598caaf858baa139407dce90e620249cde46a9d1bc4cfa21a2d2a3759?d=identicon)[TJVB](/maintainers/TJVB)

---

Top Contributors

[![manuelpichler](https://avatars.githubusercontent.com/u/58714?v=4)](https://github.com/manuelpichler "manuelpichler (865 commits)")[![ravage84](https://avatars.githubusercontent.com/u/625761?v=4)](https://github.com/ravage84 "ravage84 (502 commits)")[![kylekatarnls](https://avatars.githubusercontent.com/u/5966783?v=4)](https://github.com/kylekatarnls "kylekatarnls (465 commits)")[![frankdekker](https://avatars.githubusercontent.com/u/2179983?v=4)](https://github.com/frankdekker "frankdekker (175 commits)")[![tvbeek](https://avatars.githubusercontent.com/u/2026498?v=4)](https://github.com/tvbeek "tvbeek (152 commits)")[![eeree](https://avatars.githubusercontent.com/u/1375008?v=4)](https://github.com/eeree "eeree (33 commits)")[![AJenbo](https://avatars.githubusercontent.com/u/204594?v=4)](https://github.com/AJenbo "AJenbo (19 commits)")[![exploitfate](https://avatars.githubusercontent.com/u/1311871?v=4)](https://github.com/exploitfate "exploitfate (18 commits)")[![beberlei](https://avatars.githubusercontent.com/u/26936?v=4)](https://github.com/beberlei "beberlei (14 commits)")[![artprozorov](https://avatars.githubusercontent.com/u/188947463?v=4)](https://github.com/artprozorov "artprozorov (13 commits)")[![JeroenDeDauw](https://avatars.githubusercontent.com/u/146040?v=4)](https://github.com/JeroenDeDauw "JeroenDeDauw (12 commits)")[![smuuf](https://avatars.githubusercontent.com/u/6860713?v=4)](https://github.com/smuuf "smuuf (11 commits)")[![danepowell](https://avatars.githubusercontent.com/u/1984514?v=4)](https://github.com/danepowell "danepowell (7 commits)")[![samuelwang23](https://avatars.githubusercontent.com/u/17559596?v=4)](https://github.com/samuelwang23 "samuelwang23 (7 commits)")[![ffflabs](https://avatars.githubusercontent.com/u/238439?v=4)](https://github.com/ffflabs "ffflabs (7 commits)")[![lukasbestle](https://avatars.githubusercontent.com/u/1595007?v=4)](https://github.com/lukasbestle "lukasbestle (7 commits)")[![zerkalica](https://avatars.githubusercontent.com/u/274786?v=4)](https://github.com/zerkalica "zerkalica (6 commits)")[![jaymoulin](https://avatars.githubusercontent.com/u/14236493?v=4)](https://github.com/jaymoulin "jaymoulin (6 commits)")[![MarkVaughn](https://avatars.githubusercontent.com/u/39970?v=4)](https://github.com/MarkVaughn "MarkVaughn (6 commits)")[![sebbrandt87](https://avatars.githubusercontent.com/u/793580?v=4)](https://github.com/sebbrandt87 "sebbrandt87 (5 commits)")

---

Tags

clean-codehacktoberfestmess-detectorphppmdstatic-analysisstatic-analyzerdevpdependphpmdpmdmess detectionmess detector

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phpmd-phpmd/health.svg)

```
[![Health](https://phpackages.com/badges/phpmd-phpmd/health.svg)](https://phpackages.com/packages/phpmd-phpmd)
```

###  Alternatives

[phpstan/phpstan

PHPStan - PHP Static Analysis Tool

13.9k341.8M29.6k](/packages/phpstan-phpstan)[phpspec/prophecy

Highly opinionated mocking framework for PHP 5.3+

8.5k551.7M682](/packages/phpspec-prophecy)[pdepend/pdepend

Official version of pdepend to be handled with Composer

954110.9M815](/packages/pdepend-pdepend)[phan/phan

A static analyzer for PHP

5.6k11.2M1.1k](/packages/phan-phan)[slevomat/coding-standard

Slevomat Coding Standard for PHP\_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.

1.5k123.5M1.8k](/packages/slevomat-coding-standard)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
