2014-09-20 55 views
1

下面的重複代碼存在於兩個不同的控制器文件中,但build.xml中的複製粘貼檢測器在運行phing時不會拾取它。它生成的報告文件只是空的塊,如下所示。有人能告訴我我錯過了什麼嗎?build.xml複製+粘貼檢測器不會拾取重複的代碼

在此先感謝

探測器的報告:

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


[email protected]:$ 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 /Football/TeamBundle/Controller/Create/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" 
} 
} 
+0

你有相同手動運行phpmd命令時的結果? – COil 2014-09-21 17:37:52

+0

「總共134行代碼中有0.00%重複的行」。 – BentCoder 2014-09-21 17:49:12

+0

這很奇怪,因爲一切似乎進展順利沒有任何錯誤,但由於某種原因它不承認重複。 – BentCoder 2014-09-21 18:00:01

回答

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'; 
    } 
} 

可以更改分鐘的令牌參數默認爲70:

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

非常好,它現在可以工作:)是否有指定' - min-tokens'作爲'50'在我的build.xml入口avove? – BentCoder 2014-09-22 09:53:27

+0

查看''選項,應該是這樣的。 – COil 2014-09-22 10:02:01