File: README.rst

package info (click to toggle)
phpmd 2.9.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 3,428 kB
  • sloc: php: 14,037; xml: 1,619; makefile: 25
file content (204 lines) | stat: -rw-r--r-- 7,637 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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.

https://phpmd.org

.. 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

Installation
------------

See https://phpmd.org/download/index.html

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"
           xmlns="http://pmd.sf.net/ruleset/1.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
                         http://pmd.sf.net/ruleset_xml_schema.xsd"
           xsi:noNamespaceSchemaLocation="
                         http://pmd.sf.net/ruleset_xml_schema.xsd">
    <description>
      My custom rule set that checks my code...
    </description>

    <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" />
  </ruleset>

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"
                 endline="81"
                 rule="UnusedFormalParameter"
                 ruleset="Unused Code Rules"
                 externalInfoUrl="https://phpmd.org/rules/unusedcode.html#unusedformalparameter"
                 priority="3">
        Avoid unused parameters such as '$builder'.
      </violation>
    </file>
  </pmd>

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

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

__ 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

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.

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.

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