| 1 |
237
|
mapi |
================== |
|
| 2 |
↓
|
mapi |
Command line usage |
|
| 3 |
↓
|
mapi |
================== |
|
| 4 |
↓
|
mapi |
|
|
| 5 |
↓
|
mapi |
Type phpmd [filename|directory] [report format] [ruleset file], i.e: :: |
|
| 6 |
↓
|
mapi |
|
|
| 7 |
↓
|
mapi |
mapi@arwen ~ $ phpmd PHP/Depend/DbusUI/ xml rulesets/codesize.xml |
|
| 8 |
↓
|
mapi |
<?xml version="1.0" encoding="UTF-8" ?> |
|
| 9 |
↓
|
mapi |
<pmd version="0.0.1" timestamp="2009-12-19T22:17:18+01:00"> |
|
| 10 |
↓
|
mapi |
<file name="/projects/pdepend/PHP/Depend/DbusUI/ResultPrinter.php"> |
|
| 11 |
↓
|
mapi |
<violation beginline="67" |
|
| 12 |
↓
|
mapi |
endline="224" |
|
| 13 |
↓
|
mapi |
rule="TooManyMethods" |
|
| 14 |
↓
|
mapi |
ruleset="Code Size Rules" |
|
| 15 |
↓
|
mapi |
package="PHP_Depend\DbusUI" |
|
| 16 |
↓
|
mapi |
class="PHP_Depend_DbusUI_ResultPrinter" |
|
| 17 |
↓
|
mapi |
priority="3"> |
|
| 18 |
↓
|
mapi |
This class has too many methods, consider refactoring it. |
|
| 19 |
↓
|
mapi |
</violation> |
|
| 20 |
↓
|
mapi |
</file> |
|
| 21 |
↓
|
mapi |
</pmd> |
|
| 22 |
↓
|
mapi |
|
|
| 23 |
↓
|
mapi |
You can pass a file name or a directory name containing PHP source |
|
| 24 |
↓
|
mapi |
code to PHPMD. |
|
| 25 |
↓
|
mapi |
|
|
| 26 |
↓
|
mapi |
The PHPMD PEAR or Phar distribution includes the rule set files inside |
|
| 27 |
↓
|
mapi |
its archive, even if the "rulesets/codesize.xml" parameter above looks |
|
| 28 |
↓
|
mapi |
like a filesystem reference. |
|
| 29 |
↓
|
mapi |
|
|
| 30 |
↓
|
mapi |
Command line options |
|
| 31 |
↓
|
mapi |
==================== |
|
| 32 |
↓
|
mapi |
|
|
| 33 |
↓
|
mapi |
- Notice that the default output is in XML, so you can redirect it to |
|
| 34 |
↓
|
mapi |
a file and XSLT it or whatever |
|
| 35 |
↓
|
mapi |
|
|
| 36 |
↓
|
mapi |
- You can also use shortened names to refer to the built-in rule sets, |
|
| 37 |
↓
|
mapi |
like this: :: |
|
| 38 |
↓
|
mapi |
|
|
| 39 |
↓
|
mapi |
phpmd PHP/Depend/DbusUI/ xml codesize |
|
| 40 |
↓
|
mapi |
|
|
| 41 |
↓
|
mapi |
- The command line interface also accepts the following optional arguments: |
|
| 42 |
↓
|
mapi |
|
|
| 43 |
↓
|
mapi |
- ``--minimumpriority`` - The rule priority threshold; rules with lower |
|
| 44 |
↓
|
mapi |
priority than they will not be used. |
|
| 45 |
↓
|
mapi |
|
|
| 46 |
↓
|
mapi |
- ``--reportfile`` - Sends the report output to the specified file, |
|
| 47 |
↓
|
mapi |
instead of the default output target ``STDOUT``. |
|
| 48 |
↓
|
mapi |
|
|
| 49 |
↓
|
mapi |
- ``--extensions`` - Comma separated string of valid PHP source file |
|
| 50 |
↓
|
mapi |
extensions. |
|
| 51 |
↓
|
mapi |
|
|
| 52 |
↓
|
mapi |
- ``--ignore`` - Comma separated string of files or directories that |
|
| 53 |
↓
|
mapi |
will be ignored during the parsing process. |
|
| 54 |
↓
|
mapi |
|
|
| 55 |
↓
|
mapi |
Using multiple rule sets |
|
| 56 |
↓
|
mapi |
```````````````````````` |
|
| 57 |
↓
|
mapi |
|
|
| 58 |
↓
|
mapi |
PHPMD uses so called rule sets that configure/define a set of rules which will |
|
| 59 |
↓
|
mapi |
be applied against the source under test. The default distribution of PHPMD is |
|
| 60 |
↓
|
mapi |
already shipped with a few default sets, that can be used out-of-box. You can |
|
| 61 |
↓
|
mapi |
call PHPMD's cli tool with a set's name to apply this configuration: :: |
|
| 62 |
↓
|
mapi |
|
|
| 63 |
↓
|
mapi |
~ $ phpmd /path/to/source text codesize |
|
| 64 |
↓
|
mapi |
|
|
| 65 |
↓
|
mapi |
But what if you would like to apply more than one rule set against your source? |
|
| 66 |
↓
|
mapi |
You can also pass a list of rule set names, separated by comma to PHPMD's cli |
|
| 67 |
↓
|
mapi |
tool: :: |
|
| 68 |
↓
|
mapi |
|
|
| 69 |
↓
|
mapi |
~ $ phpmd /path/to/source text codesize,unusedcode,naming |
|
| 70 |
↓
|
mapi |
|
|
| 71 |
↓
|
mapi |
You can also mix custom `rule set files`__ with build-in rule sets: :: |
|
| 72 |
↓
|
mapi |
|
|
| 73 |
↓
|
mapi |
~ $ phpmd /path/to/source text codesize,/my/rules.xml |
|
| 74 |
↓
|
mapi |
|
|
| 75 |
↓
|
mapi |
__ /documentation/creating-a-ruleset.html |
|
| 76 |
↓
|
mapi |
|
|
| 77 |
↓
|
mapi |
That's it. With this behavior you can specify you own combination of rule sets |
|
| 78 |
↓
|
mapi |
that will check the source code. |
|
| 79 |
↓
|
mapi |
|
|
| 80 |
↓
|
mapi |
Exit codes |
|
| 81 |
↓
|
mapi |
========== |
|
| 82 |
↓
|
mapi |
|
|
| 83 |
↓
|
mapi |
PHPMD's command line tool currently defines three different exit codes. |
|
| 84 |
↓
|
mapi |
|
|
| 85 |
↓
|
mapi |
- *0*, This exit code indicates that everything worked as expected. This means |
|
| 86 |
↓
|
mapi |
there was no error/exception and PHPMD hasn't detected any rule violation |
|
| 87 |
↓
|
mapi |
in the code under test. |
|
| 88 |
↓
|
mapi |
- *1*, This exit code indicates that an error/exception occured which has |
|
| 89 |
↓
|
mapi |
interrupted PHPMD during execution. |
|
| 90 |
↓
|
mapi |
- *2*, This exit code means that PHPMD has processed the code under test |
|
| 91 |
↓
|
mapi |
without the occurence of an error/exception, but it has detected rule |
|
| 92 |
↓
|
mapi |
violations in the analyzed source code. |
|
| 93 |
↓
|
mapi |
|
|
| 94 |
↓
|
mapi |
Renderers |
|
| 95 |
↓
|
mapi |
========= |
|
| 96 |
↓
|
mapi |
|
|
| 97 |
↓
|
mapi |
At the moment PHPMD comes with the following three renderers: |
|
| 98 |
↓
|
mapi |
|
|
| 99 |
↓
|
mapi |
- *xml*, which formats the report as XML. |
|
| 100 |
↓
|
mapi |
- *text*, simple textual format. |
|
| 101 |
↓
|
mapi |
- *html*, single HTML file with possible problems. |
|