PHPMD是PHP Depend的一个分拆项目,旨在成为与其熟知的Java工具PMD相当的PHP版本。 PHPMD可以被看作是由PHP Depend测量的原始度量流的用户友好的前端应用程序。
PHPMD做的是:它需要一个给定的PHP源代码库,并寻找该源中的几个潜在问题。 这些问题可以是:
- 可能的错误
- 次优码
- 过于简单的表达
- 未使用的参数,方法,属性
PHPMD - PHP混乱探测器。(PHPMD - PHP Mess Detector.)
PHPMD是PHP Depend的一个分拆项目,旨在成为与其熟知的Java工具PMD相当的PHP版本。 PHPMD可以被看作是由PHP Depend测量的原始度量流的用户友好的前端应用程序。
名称与所有者 | phpmd/phpmd |
---|---|
主编程语言 | PHP |
编程语言 | PHP (语言数: 4) |
平台 | |
许可证 | BSD 3-Clause "New" or "Revised" License |
创建于 | 2011-01-29 21:51:55 |
---|---|
推送于 | 2025-04-07 18:47:38 |
最后一次提交 | 2025-02-10 16:04:03 |
发布数 | 61 |
最新版本名称 | 2.15.0 (发布于 ) |
第一版名称 | 0.2.3 (发布于 ) |
星数 | 2.4k |
---|---|
关注者数 | 51 |
派生数 | 346 |
提交数 | 2.6k |
已启用问题? | |
问题数 | 597 |
打开的问题数 | 133 |
拉请求数 | 529 |
打开的拉请求数 | 20 |
关闭的拉请求数 | 92 |
已启用Wiki? | |
---|---|
已存档? | |
是复刻? | |
已锁定? | |
是镜像? | |
是私有? |
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.
.. image:: https://poser.pugx.org/phpmd/phpmd/v/stable.svg
:target: https://packagist.org/packages/phpmd/phpmd
:alt: Latest Stable Version
.. image:: https://poser.pugx.org/phpmd/phpmd/license.svg
:target: https://packagist.org/packages/phpmd/phpmd
:alt: License
.. image:: https://travis-ci.org/phpmd/phpmd.svg?branch=master
:target: https://travis-ci.org/phpmd/phpmd
:alt: Travis Build Status
.. image:: https://ci.appveyor.com/api/projects/status/pc08owbun2y00kwk?svg=true
:target: https://ci.appveyor.com/project/phpmd/phpmd
:alt: AppVeyor Build Status
.. image:: https://scrutinizer-ci.com/g/phpmd/phpmd/badges/build.png?b=master
:target: https://scrutinizer-ci.com/g/phpmd/phpmd/build-status/master
:alt: Scrutinizer Build Status
.. image:: https://scrutinizer-ci.com/g/phpmd/phpmd/badges/quality-score.png?b=master
:target: https://scrutinizer-ci.com/g/phpmd/phpmd/?branch=master
:alt: Scrutinizer Code Quality
.. image:: https://badges.gitter.im/phpmd/community.svg
:target: https://gitter.im/phpmd/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge
:alt: Chat with us on Gitter
.. image:: https://poser.pugx.org/phpmd/phpmd/d/monthly
:target: https://packagist.org/packages/phpmd/phpmd
:alt: Monthly downloads
.. image:: https://poser.pugx.org/phpmd/phpmd/downloads
:target: https://packagist.org/packages/phpmd/phpmd
:alt: Total downloads
See https://phpmd.org/download/index.html
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::
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::
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.
__ https://phpmd.org/download/index.html
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.
--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
__ https://phpmd.org/documentation/creating-a-ruleset.html
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
PHPMD's command line tool currently defines three different exit codes.
--ignore-violations-on-exit
flag, which will result to a 0At the moment PHPMD comes with the following renderers:
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.
__