C.70 PHPMDTask

This task runs phpmd, a Project Mess Detector (PMD) for PHP Code. You need an installed version of this software to use this task.

NB: if you have installed the PHPMD Phar file, make sure you set the pharLocation attribute!

Table C.93: Attributes

fileStringPath to source file or pathn/aOnly when there are no nested fileset elements
rulesetsStringSets the rulesets used for analyzing the source codecodesize, unusedcodeNo
minimumPriorityIntegerThe minimum priority for rules to load.5No
allowedFileExtensionsStringComma-separated list of valid file extensions (without dot) for analyzed files.phpNo
ignorePatternsStringComma-separated list of directory patterns to ignore..git, .svn, CVS, .bzr, .hgNo
formatStringThe format for the report when no nested formatter is used.textNo
pharlocationStringLocation of the PHPMD Phar file.n/aNo
cachefileStringIf set, enables writing of last-modified times to cachefile, to speed up processing of files that rarely changenoneNo

C.70.1 Example

<phpmd file="path/to/source.php"/>

Checking syntax of one particular source file. Sending Text-Report to STDOUT.

<phpmd file="path/to/source">
   <formatter type="html" outfile="reports/pmd.html"/>

Checking syntax of source files in the given path.

   <fileset dir="${builddir}">
     <include name="apps/**/*.php" />
     <include name="lib/de/**/*.php" />
   <formatter type="xml" outfile="reports/pmd.xml"/>

Checking syntax of source files in the fileset pathes.

C.70.2 Supported Nested Tags

  • fileset

    This nested tag is required when the file attribute is not set.

  • formatter

    The results of the analysis can be printed in different formats. Output will always be sent to STDOUT, unless you set the usefile attribute to true and set an filename in the outfile attribute.

    Table C.94: Attributes

    typeStringThe output format. Accepts the same values as the format attribute (xml, html, text).n/aYes
    usefileBooleanBoolean that determines whether output should be sent to a file.trueNo
    outfileStringPath to write output file to.n/aYes