This task runs phpcpd, a Copy/Paste Detector (CPD) for PHP Code. You need an installed version of this software to use this task.

NB: if you have installed the PHPCPD PHAR, make sure you set the pharlocation attribute!

Table C.89: Attributes

fileStringPath to source file or pathn/aOnly when there are no nested fileset elements
minTokensIntegerSets the minimum number of identical tokens (default: 70)70No
minLinesIntegerSets the minimum number of identical lines (default: 5)5No
formatStringThe format for the report when no nested formatter is used.defaultNo
fuzzyBooleanIf fuzzy is set to true, the task will perform a fuzzy match.falseNo
pharlocationStringLocation of the PHPCPD PHAR package.n/aNo

C.68.1 Examples

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

Checking for copy/paste code in one particular source file. Sending Default-Report to STDOUT.

<phpcpd file="path/to/source">
   <formatter type="pmd" outfile="reports/pmd-cpd.xml"/>

Checking for copy/paste code in files of the given path.

   <fileset dir="${builddir}" id="filestocpd">
     <include name="apps/**/*.php" />
     <include name="lib/de/**/*.php" />
     <include name="lib/task/**/*.php" />
     <include name="lib/services/**/*.php" />
     <include name="lib/form/**/*.php" />
     <include name="lib/model/**/*.php" />
   <formatter type="pmd" outfile="reports/pmd-cpd.xml"/>

C.68.2 Supported Nested Tags

  • fileset

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

  • formatter

    The results of the copy/paste scan can be printed in different formats. Output will always be sent to a file, unless you set the usefile attribute to false.

    Table C.90: Attributes

    typeStringThe output format. Accepts the same values as the format attribute (default, pmd).n/aYes
    useFileBooleanFlag that determines whether output should be sent to a file or not.trueNo
    outfileStringPath to write output file to.n/aYes