build.xml copy + paste detector不会获取重复的代码

时间:2014-09-20 20:08:26

标签: symfony phing phpmd

下面的重复代码存在于两个不同的控制器文件中,但build.xml中的复制粘贴检测器在运行phing时不会启动它。它生成的报告文件只有空块,如下所示。有人能告诉我我错过了什么吗?

提前致谢

探测器的报告:

<?xml version="1.0" encoding="UTF-8"?>
<pmd-cpd/>


zzz@ubuntu:$ bin/phpcpd src/Foo/TeBundle/Controller/Create/LeController.php 
phpcpd 2.0.1-5-ga7488a0 by Sebastian Bergmann.

0.00% duplicated lines out of 134 total lines of code.

Time: 25 ms, Memory: 3.00Mb
  • 控制器1: SRC /足球/ TeamBundle /控制器/创建/ CountryController.php
  • 控制器2: SRC /足球/ TeamBundle /控制器/创建/ CityController.php

重复编码:

public function indexAction()
{
    $form = $this->getForm();

    if (is_null($form)) {
        echo 'form empty';
    } else {
        echo 'not empty';
    }
}

public function indexAction()
{
    $form = $this->getForm();

    if (is_null($form)) {
        echo 'form empty';
    } else {
        echo 'not empty';
    }
}

的build.xml

<?xml version="1.0" encoding="UTF-8"?>

<project name="Sport" default="detect-copy-paste" basedir=".">

    <!-- GLOBAL VARIABLES -->
    <property name="dir-source" value="${project.basedir}/src" />
    <property name="dir-report" value="test/report/phing" />
    <!-- END -->

    <!-- FILESET -->
    <fileset id="sourcecode" dir="${dir-source}">
        <include name="**/*.php" />
    </fileset>
    <!-- END -->


    <!-- COPY and PASTE DETECTOR -->
    <target name="detect-copy-paste" description="Checks similar code blocks.">
        <echo msg="Checking similar code blocks ..." />
        <phpcpd>
            <fileset refid="sourcecode" />
            <formatter type="pmd" outfile="${dir-report}/copypaste.xml" />
        </phpcpd>
    </target>
    <!-- END -->

</project>

COMPOSER.JSON

{
    "autoload": {
        "psr-0": {
            "": "src/",
            "SymfonyStandard": "app/"
        }
    },
"require": {
    "php": ">=5.3.3",
    "symfony/symfony": "2.5.*",
    "doctrine/orm": "~2.2,>=2.2.3",
    "doctrine/doctrine-bundle": "~1.2",
    "twig/extensions": "~1.0",
    "symfony/assetic-bundle": "~2.3",
    "symfony/swiftmailer-bundle": "~2.3",
    "symfony/monolog-bundle": "~2.4",
    "sensio/distribution-bundle": "~3.0",
    "sensio/framework-extra-bundle": "~3.0",
    "incenteev/composer-parameter-handler": "~2.0",
    "behat/behat": "2.5.*@stable",
    "behat/behat-bundle": "1.0.0",
    "behat/symfony2-extension": "1.1.2",
    "behat/mink": "1.5.0",
    "behat/mink-extension": "~1.3",
    "behat/mink-selenium2-driver": "1.1.1",
    "behat/mink-goutte-driver": "1.0.9",
    "phing/phing": "2.8.2",
    "squizlabs/php_codesniffer": "1.5.1",
    "doctrine/doctrine-fixtures-bundle": "2.2.*",
    "pdepend/pdepend": "2.0.*",
    "phpmd/phpmd" : "2.0.*",
    "sebastian/phpcpd": "@dev",
    "sebastian/finder-facade": "~1.1",
    "sebastian/version": "~1.0.3",
    "symfony/console": "~2.2",
    "phpunit/php-timer": "~1.0.4",
    "theseer/fdomdocument": "~1.4"
}
}

1 个答案:

答案 0 :(得分:1)

未检测到重复的代码,因为令牌数量不足是您的代码段,将检测到以下内容:

public function indexAction()
{
    $form = $this->getForm('kikoo');

    if (is_null($form)) {
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
        echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty'; echo 'form empty';
    } else {
        echo 'not empty';
    }
}

您可以更改min-tokens参数,默认为70:

phpcpd src/ --progress --min-lines=5 --min-tokens=70