Giter Site home page Giter Site logo

phpcpd's Introduction

This project is no longer maintained and its repository is only kept for archival purposes.

PHP Copy/Paste Detector (PHPCPD)

phpcpd is a Copy/Paste Detector (CPD) for PHP code.

Installation

This tool is distributed as a PHP Archive (PHAR):

$ wget https://phar.phpunit.de/phpcpd.phar

$ php phpcpd.phar --version

Using Phive is the recommended way for managing the tool dependencies of your project:

$ phive install phpcpd

$ ./tools/phpcpd --version

It is not recommended to use Composer to download and install this tool.

Usage Example

$ php phpcpd.phar --fuzzy wordpress-5.5
phpcpd 6.0.0 by Sebastian Bergmann.

Found 121 clones with 8137 duplicated lines in 69 files:

  - /home/sb/wordpress-5.5/wp-includes/sodium_compat/src/Core/Curve25519/H.php:19-1466 (1447 lines)
    /home/sb/wordpress-5.5/wp-includes/sodium_compat/src/Core32/Curve25519/H.php:19-1466
.
.
.
  - /home/sb/wordpress-5.5/wp-includes/sodium_compat/src/Core32/Curve25519.php:879-889 (10 lines)
    /home/sb/wordpress-5.5/wp-includes/sodium_compat/src/Core32/Curve25519.php:1072-1082

1.82% duplicated lines out of 446676 total lines of code.
Average size of duplication is 67 lines, largest clone has 1447 of lines

Time: 00:02.980, Memory: 318.00 MB

phpcpd's People

Contributors

aboks avatar ajardin avatar alexshadow007 avatar edorian avatar g-g avatar globin avatar gooh avatar grahamcampbell avatar henriquemoody avatar jeroendedauw avatar jpetitcolas avatar jsobiecki avatar keradus avatar kukulich avatar localheinz avatar lsv avatar mrenrcert avatar oallain avatar ocramius avatar olleharstedt avatar padawin avatar petah avatar remicollet avatar sebastianbergmann avatar sergeyz avatar svemir avatar tommygnr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phpcpd's Issues

Can't Install via Composer

First off -- thanks for making this!

Not sure if anyone else has run into this issue, but can't install via Composer:

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for sebastian/phpcpd * -> satisfiable by sebastian/phpcpd[1.4.1].
    - sebastian/phpcpd 1.4.1 requires sebastian/finder-facade dev-master -> no matching package found.

Looked through #58, but didn't see anything about this.

TheSeer/fDOMDocument required

PHP Warning: require_once(TheSeer/fDOMDocument/autoload.php): failed to open stream: No such file or directory in /usr/share/pear/SebastianBergmann/FinderFacade/autoload.php on line 53

I've installed "phpcpd" from PEAR channel according to official instructions here:
https://github.com/sebastianbergmann/phpcpd

Resolved the problem by installing the pear package:

sudo pear channel-discover pear.netpirates.net
sudo pear install TheSeer/fDOMDocument

Fatal Error

Hi.

I pulled my repository and found the problem.

Warning: require_once(File/Iterator/Autoload.php): failed to open stream: No such file or directory in /usr/share/php/phpcpd/PHPCPD/Autoload.php on line 44

I checked in File Iterator and didn't find this file. Can you help me?

Thanks

Warning emitted for similar blocks of code with differences in comments

I have three similar exception classes, however, they are not identical. Yet, I am still getting a copy/paste warning for them.

Here are the three blocks of code:

File 1:

use BreakMedia\Api as Api;

/**
 * Custom exception class for Search exceptions.
 *
 * @package BreakMedia\Api
 * @subpackage Server\Search
 */
class Exception extends Api\Server\ServiceException

File 2:

use BreakMedia\Api as Api;

/**
 * Custom exception class for the Encode service.
 *
 * @package BreakMedia\Api
 * @subpackage Server\Encode
 */
class Exception extends Api\Server\ServiceException

File 3:

use BreakMedia\Api as Api;

/**
 * Custom exception class for Callback exceptions.
 *
 * @package BreakMedia\Api
 * @subpackage Server\Callback
 */
class Exception extends Api\Server\ServiceException

Is it possible to search for duplicate code on different files in the same project?

Greetings.
I am still new to phpcpd, but I think it could really become one of my favorite tools.

I am trying trying to detect duplicate code on different files, belonging to the same project.
I am currently working on old stuff to renew, and I can find lots of cut-paste issues.

Nevertheless I have the impression that phpcpd allows only to find duplicate code inside each file, not comparing the contents of a file to another different one.
Can you confirm this?

Is there a way to find any possible duplicate code in a project (no problem of memory nor time), examining all existing files, with your tool?

Thank you for your feedback.
Cheers
Emanuele

php.ini settings on command line

I have a need for php.ini settings on the command line invocation, or at least a way to bump the default memory. I'm getting an out of memory and I'd like to keep my php.ini default so the remainder of my CI stack can run against the prod settings.

Use pattern-based exclude and including options

For instance, for using generators (specifically in symfony) I get lots of BaseForm...class.php that have very similar parts...

Those generated classes always come in sub-folders called "base", so it would be great for me if I could exclude all the sub-folders that have "base".

It would also be great to exclude files based on other patterns, such as the first characters of the file (all symfony classes start with "sf"), etc.

--exclude commandline param processing error

Hi,

I saw sam previous issues regarding this but after some debugging I saw an little error in: https://github.com/sebastianbergmann/phpcpd/blob/master/PHPCPD/TextUI/Command.php (lines 194 through 196)

        if (is_array($exclude) && (count($exclude) == 1)) {
            array_map('trim', explode(',', array_pop($exclude)));
        }

$exclude is used afterwards but because of array_pop the array is cleared there is only one --exclude param specified.

Here is how I think it should look like:

        if (is_array($exclude) && (count($exclude) == 1)) {
            $exclude = array_map('trim', explode(',', array_pop($exclude)));
        }

Best reagrds,
Fran

Can't install

Session output:

Attempting to discover channel "components.ez.no"...
Attempting fallback to https instead of http on channel "components.ez.no"...
Unknown remote channel: components.ez.no
phpunit/phpcpd requires package "channel://components.ez.no/ConsoleTools" (version >= 1.6)
No valid packages found
install failed

False positives including namespace and use directives

Hello,
Since introduction of namespace and use keywords in PHP5.3 and their widespread use in frameworks like Symfony2, a lot of duplication appear in PHPCPD concerning theses keywords. The duplications reported are of no use. Is it possible to ignore these directives ?

--exclude parameter is ignored

I issued the command as follows:

phpcpd --log-pmd ../build/logs/phpcpd.xml --exclude upstream --verbose .

but upstream is still included in the output, which is evidenced by the fact that the output statistics for my source tree match exactly with the following command:

phpcpd --log-pmd ../build/logs/phpcpd.xml --verbose .

Issue with mbstring.func_overload - Multiple wrong reports for a specific File.

Hi, i found out there is a issue with phpcpd if you have mbstring_funcoverload enabled (i had it set to 6). phpcpd then generates multiple matches for a random File in the Project, and seems to jumble up line numbers. Setting this in the phpcpd code fixes the problem.

ini_set('mbstring.func_overload', 0);
ini_set('mbstring.internal_encoding', null);

I do not have the guts to do it myself, because there may be a better solution, like including mbstring support ... hth paul

If any one of --names, --names-exclude, or --exclude is used, all must be used

If I try to use just --names-exclude, for example, I get the following:

$ vendor/bin/phpcpd --names-exclude "index.php,phpunit.bootstrap.php" products/
phpcpd 2.0-g206c2fc by Sebastian Bergmann.

PHP Catchable fatal error:  Argument 4 passed to SebastianBergmann\FinderFacade\FinderFacade::__construct() must be of the type array, string given, called in /code/vendor/sebastian/phpcpd/src/CLI/Command.php on line 149 and defined in /code/vendor/sebastian/finder-facade/src/FinderFacade.php on line 87
PHP Stack trace:
PHP   1. {main}() /code/vendor/sebastian/phpcpd/composer/bin/phpcpd:0
PHP   2. Symfony\Component\Console\Application->run() /code/vendor/sebastian/phpcpd/composer/bin/phpcpd:71
PHP   3. SebastianBergmann\PHPCPD\CLI\Application->doRun() /code/vendor/symfony/console/Symfony/Component/Console/Application.php:121
PHP   4. Symfony\Component\Console\Application->doRun() /code/vendor/sebastian/phpcpd/src/CLI/Application.php:135
PHP   5. Symfony\Component\Console\Application->doRunCommand() /code/vendor/symfony/console/Symfony/Component/Console/Application.php:191
PHP   6. Symfony\Component\Console\Command\Command->run() /code/vendor/symfony/console/Symfony/Component/Console/Application.php:897
PHP   7. SebastianBergmann\PHPCPD\CLI\Command->execute() /code/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
PHP   8. SebastianBergmann\FinderFacade\FinderFacade->__construct() /code/vendor/sebastian/phpcpd/src/CLI/Command.php:149

Catchable fatal error: Argument 4 passed to SebastianBergmann\FinderFacade\FinderFacade::__construct() must be of the type array, string given, called in /code/vendor/sebastian/phpcpd/src/CLI/Command.php on line 149 and defined in /code/vendor/sebastian/finder-facade/src/FinderFacade.php on line 87

Call Stack:
    0.0001     229144   1. {main}() /code/vendor/sebastian/phpcpd/composer/bin/phpcpd:0
    0.0178    1542376   2. Symfony\Component\Console\Application->run() /code/vendor/sebastian/phpcpd/composer/bin/phpcpd:71
    0.0226    1869200   3. SebastianBergmann\PHPCPD\CLI\Application->doRun() /code/vendor/symfony/console/Symfony/Component/Console/Application.php:121
    0.0228    1869744   4. Symfony\Component\Console\Application->doRun() /code/vendor/sebastian/phpcpd/src/CLI/Application.php:135
    0.0229    1870672   5. Symfony\Component\Console\Application->doRunCommand() /code/vendor/symfony/console/Symfony/Component/Console/Application.php:191
    0.0229    1871040   6. Symfony\Component\Console\Command\Command->run() /code/vendor/symfony/console/Symfony/Component/Console/Application.php:897
    0.0233    1875112   7. SebastianBergmann\PHPCPD\CLI\Command->execute() /code/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:244
    0.0237    1892192   8. SebastianBergmann\FinderFacade\FinderFacade->__construct() /code/vendor/sebastian/phpcpd/src/CLI/Command.php:149

I added InputOption::VALUE_IS_ARRAY to the addOption() call in Command.php ( lines 83 & 90 ), and that seems to fix it complaining about the arguments not being arrays. However, with those lines added, it still doesn't work. I'm not sure if I'm just not using the arguments correctly or what, but I can't seem to use --names, --names-exclude, or --exclude properly. I can't seem to get any of these command line options to work.

Line count calculation bug causes detection misses

Using the default settings for min-lines and min-tokens, the following two blocks aren't detected as duplicates, although they meet both requirements.

<?php
function dupeA() {
    for ($i = 0; $i < 10; $i++) {
        echo 123, 123, 123, 123, 123, 123, 123, 123;
        echo 124, 123, 123, 123, 123, 123, 123, 123;
        echo 125, 123, 123, 123, 123, 123, 123, 123;
        echo 126, 123, 123, 123, 123, 123, 123, 123;
        echo 127, 123, 123, 123, 123, 123, 123, 123;
        echo 128, 123, 123, 123, 123, 123, 123, 123;
        echo 129, 123, 123, 123, 123, 123, 123, 123;
    }
}

function dupeB() {
    for ($i = 0; $i < 10; $i++) {
        echo 123, 123, 123, 123, 123, 123, 123, 123;
        echo 124, 123, 123, 123, 123, 123, 123, 123;
        echo 125, 123, 123, 123, 123, 123, 123, 123;
        echo 126, 123, 123, 123, 123, 123, 123, 123;
        echo 127, 123, 123, 123, 123, 123, 123, 123;
        echo 128, 123, 123, 123, 123, 123, 123, 123;
        echo 129, 123, 123, 123, 123, 123, 123, 123;
    }
}

The reason for this is in the default detector strategy, which only looks at the starting line for the set of tokens it currently checks. But of course the required 70 tokens are spread across multiple lines, so instead of only looking for the line of the first token in this block, you also have to check the last one.

A somewhat crude fix is here: https://gist.github.com/3176121

Add support for Duplication Chains and Line Bias

From "Object-Oriented Metrics in Practice":

  • Line Bias is the distance between two consecutive Exact Clones.
  • A Duplication Chain is composed of a number of smaller islands of Exact Clones that are close enough pairwise to be considered as belonging together, i.e. their Line Bias value is less than a given threshold.

Incorrect reporting of duplicated lines when duplication occurs near end of tokens

The loop over the lines of a file terminates early when there are fewer than $minTokens left (since no new duplication of suitable length could be discovered after this point). However, this has the side effect of not setting $line to any line number after this point, resulting in the final if ($found) clause reporting the wrong line numbers or not reporting at all if part of a duplicated code bit takes place within this area.

The easy fix is:

--- a/PHPCPD/Detector.php
+++ b/PHPCPD/Detector.php
@@ -167,7 +167,7 @@ class PHPCPD_Detector
                     }

                     $tokenNr++;
-                } while ($tokenNr <= (count($currentTokenPositions) - $minTokens) + 1);
+                } while ($tokenNr <= count($currentTokenPositions) - 1);
             }

             if ($found) {

Endless loop for directories that contain no .php files

If I run phpcpd on a directory that contains no .php files (completely empty or otherwise), I see a bunch of messages that look like this:

Notice:  Undefined offset: 0 in /usr/share/pear/File/Iterator/Facade.php on line 145
Stack trace:
  1. {main}() /usr/bin/phpcpd:0
  2. PHPCPD_TextUI_Command::main() /usr/bin/phpcpd:50
  3. File_Iterator_Facade->getFilesAsArray($paths = array (0 => '/path/to/dir/'), $suffixes = array (0 => 'php'), $prefixes = array (), $exclude = array (), $commonPath = TRUE) /usr/share/pear/PHPCPD/TextUI/Command.php:209
  4. File_Iterator_Facade->getCommonPath($files = array ()) /usr/share/pear/File/Iterator/Facade.php:99

This is similar to Issue 21.

--exclude not working in version 1.4.0

Recently i discovered that --exclude does not exclude the specified folders. It has to do with the parsing of the exclude string, which is broken in that version.

A fix is to modify the file "src/TextUI/Command.php". At line 202 it should look like this

$excludes   = $input->getOption('exclude')->value;
if (is_array($excludes) && count($excludes == 1)) {
    $excludes   = explode(',', $excludes[0]);
}

With this modification --exclude will work as intended. Dont forget to use relative paths.

phpcpd failed when using "phpcpd ."

php version : 5.4.10

error_reporting :

phpcpd 1.4.0 by Sebastian Bergmann.

Fatal error: Class 'Symfony\Component\Finder\Adapter\GnuFindAdapter' not found in /home/users/wangjing14/tools/php/php54/lib/php/Symfony/Component/Finder/Finder.php on line 69

Endless Loop in Command.php when scanning and folder with 1 php and 1 swapfile

Letting phpcpd run against a folder that looks like this:

edo@edo:~/PHP/phpcpd$ ls -als source/
total 24
  4 drwxr-xr-x 2 edo edo  4096 2011-02-22 21:04 .
  4 drwxr-xr-x 6 edo edo  4096 2011-02-22 20:12 ..
  4 -rw-r--r-- 1 edo edo  2652 2011-02-22 17:39 String.php
 12 -rw-r--r-- 1 edo edo 12288 2011-02-22 21:04 .String.php.swp

Creates and endless loop

phpcpd @package_version@ by Sebastian Bergmann.

PHP Notice:  Undefined offset: 7 in /home/edo/PHP/phpcpd/PHPCPD/TextUI/Command.php on line 263
PHP Stack trace:
PHP   1. {main}() /home/edo/PHP/phpcpd/phpcpd.php:0
PHP   2. PHPCPD_TextUI_Command::main() /home/edo/PHP/phpcpd/phpcpd.php:51
PHP   3. PHPCPD_TextUI_Command::getCommonPath() /home/edo/PHP/phpcpd/PHPCPD/TextUI/Command.php:218

and so on.

That seems to be cause by a strange return of File_Iterator (version 1.2.3 & head of master branch)

197         var_dump($arguments);
198         var_dump($suffixes);
199         var_dump($exclude);
200         if (!empty($arguments)) {
201             $files = File_Iterator_Factory::getFilesAsArray(
202               $arguments, $suffixes, array(), $exclude
203           );
204             var_dump($files);

Shows:

array(1) {
  [0]=>
  string(7) "source/"
}
array(1) {
  [0]=>
  string(3) "php"
}
array(0) {
}
array(2) {
  [0]=>
  string(38) "/home/edo/PHP/phpcpd/source/String.php"
  [1]=>
  string(38) "/home/edo/PHP/phpcpd/source/String.php"
}

I'm going to send you some tests for File_Iterator but i was not able to reproduce the problem for now.

I cared the bug for PHPCPD because I'm not sure if thats a problem of File_Iterator of the usage of the lib.

Feel free to close :)

Support for incremental scans

Running the phpcpd on a large code base in the context of continuous integration can be time consuming, it can take more than 2 or 3 minutes.

With incremental scans this could be used in a pre commit hook as a rule to accept the commit, supposing it could be executed only on the commited files with a "decent" response time.

--exclude comma delimitation removed

Was just curious if there was any reason why the comma delimitation support in phpcpd's --exclude was removed.

Was it removed due to buginess, or...? j/w

-JP

memory overflow ?

[exec] PHP Fatal error:  Maximum function nesting level of '100' reached, aborting! in C:\PHP\pear\SebastianBergmann\Version\Version.php on line 125
     [exec] PHP Stack trace:
     [exec] PHP   1. {main}() C:\PHP\phpcpd:0
     [exec] PHP   2. SebastianBergmann\PHPCPD\TextUI\Command->__construct() C:\PHP\phpcpd:55
     [exec] PHP   3. SebastianBergmann\Version->getVersion() C:\PHP\pear\SebastianBergmann\PHPCPD\TextUI\Command.php:68
     [exec] PHP   4. SebastianBergmann\Version->getGitInformation() C:\PHP\pear\SebastianBergmann\Version\Version.php:81
     [exec] PHP   5. SebastianBergmann\Version->isGitRepository() C:\PHP\pear\SebastianBergmann\Version\Version.php:103
     [exec] PHP   6. SebastianBergmann\Version->isGitRepository() C:\PHP\pear\SebastianBergmann\Version\Version.php:135

Then it will repeat the last line "PHP 6. SebastianBergmann\Version->isGitRepository() C:\PHP\pear\SebastianBergmann\Version\Version.php:135" until it reaches 100 levels.

Call stack looks the same:

[exec] Call Stack:
     [exec]     0.0008     124120   1. {main}() C:\PHP\phpcpd:0
     [exec]     0.0073     340792   2. SebastianBergmann\PHPCPD\TextUI\Command->__construct() C:\PHP\phpcpd:55
     [exec]     0.0077     351624   3. SebastianBergmann\Version->getVersion() C:\PHP\pear\SebastianBergmann\PHPCPD\TextUI\Command.php:68
     [exec]     0.0077     351760   4. SebastianBergmann\Version->getGitInformation() C:\PHP\pear\SebastianBergmann\Version\Version.php:81
     [exec]     0.0077     351800   5. SebastianBergmann\Version->isGitRepository() C:\PHP\pear\SebastianBergmann\Version\Version.php:103
     [exec]     0.0078     351928   6. SebastianBergmann\Version->isGitRepository() C:\PHP\pear\SebastianBergmann\Version\Version.php:135

Missing Directory Separators

I have an ant target in my project to run phpcpd:

<target name="phpcpd">
    <!--unix-->
    <exec
      executable="phpcpd"
       failonerror="true" osfamily="unix">
        <arg line="--min-tokens 10 ${basedir}"/>
    </exec>
</target>

It spits out the findings without the directory separators:

varwwwwebads_newviewsindex.php:4-21
varwwwwebads_newviewspartialnav.php:5-22
[... snip ...]

Add support for ignoring directories/files

It would be very helpful to be able to instruct phpcpd to ignore certain files or directories when generating a report (for example, to leave out third-party library code).

I've implemented this feature at youngian/phpcpd@2808ddaeb1830de8ddf3a756c21a52bbde00e231 - my version uses simple text matching against a comma-delimited list. Other ways of implementing this could include bash-like globbing or a regular expression.

Error with report in PMD-CPD XML format to file

I'm not able to use it in TeamCity here is a part of log:

[20:01:04]: Failed to parse D:\TeamCity\buildAgent\work\2ced091824a6e6f3\build\logs\phpcpd.xml with PMD parser
[20:01:04]: Failed to process some PMD reports

P. S.
XML log of phpmd works fine in TeamCity.

PHPCPD showes wrong results on not exaxtly same code

I'm not sure if this is an issue or a feature. I got following results from phpcpd as "exact clones".

[php file 1]
46 foreach ($items->entry as $item) {
47 $result[] = $this->refineFromXml($item);
48 }
49 }
50 }
51
52 return new Collection($result);

[php file 2]
50 foreach ($xml->newsitems->webnewsitem as $item) {
51 $result[] = $this->refineFromXml($item);
52 }
53 }
54 }
55
56 return new Collection($result);

But the line of foreach token is not exactly same. Is phpcpd also looking for copy-paste-edit pattern? Thanks in advance for your help!

Endless loop due to file being read twice

When I try to run phpcpd against a folder it gets stuck in an endless loop throwing the following error:

...
PHP Notice:  Undefined offset: 169 in /usr/share/php/PHPCPD/TextUI/Command.php on line 260
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpcpd:0
PHP   2. PHPCPD_TextUI_Command::main() /usr/bin/phpcpd:51
PHP   3. PHPCPD_TextUI_Command::getCommonPath() /usr/share/php/PHPCPD/TextUI/Command.php:219
PHP Notice:  Undefined offset: 170 in /usr/share/php/PHPCPD/TextUI/Command.php on line 267
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpcpd:0
PHP   2. PHPCPD_TextUI_Command::main() /usr/bin/phpcpd:51
PHP   3. PHPCPD_TextUI_Command::getCommonPath() /usr/share/php/PHPCPD/TextUI/Command.php:219
...

I id a bit of digging and it appears that this is because the directory iterator in File_Iterator_Factory is returning the same file twice:

object(File_Iterator)#21 (4) {
  ["suffixes":protected]=>
  array(2) {
    [0]=>
    string(3) "php"
    [1]=>
    string(5) "phtml"
  }
 ["prefixes":protected]=>
  array(0) {
  }
  ["exclude":protected]=>
  array(0) {
  }
  ["basepath":protected]=>
  string(55) "/home/nick/.hudson/jobs/project/workspace/svn/www"
}
object(SplFileInfo)#25 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "svn/www/index.php"
  ["fileName":"SplFileInfo":private]=>
  string(9) "index.php"
}
object(SplFileInfo)#26 (2) {
  ["pathName":"SplFileInfo":private]=>
  string(17) "svn/www/index.php"
  ["fileName":"SplFileInfo":private]=>
  string(9) "index.php"
}

which causes it to never break out of the loop. There is only one file in there. As a temporary solution I've put an array_unique in to remove duplicates, but this seems to be ignoring the root cause?

Can't find 'PHPUnit_Framework_MockObject_Generator'

The call in my test file:
$engine = $this->getMock('PackedFileDataStore');
results in:

PHP Fatal error: Class 'PHPUnit_Framework_MockObject_Generator' not found in /usr/share/php/PHPUnit/Framework/TestCase.php on line 1049

there is a error when I use phpcpd

phpcpd --log-pmd ./build/logs/phploc.csv ./
phpcpd 1.4.0 by Sebastian Bergmann.

PHP Fatal error: Class 'Symfony\Component\Finder\Adapter\GnuFindAdapter' not found in /usr/share/pear/Symfony/Component/Finder/Finder.php on line 69
PHP Stack trace:
PHP 1. {main}() /usr/bin/phpcpd:0
PHP 2. SebastianBergmann\PHPCPD\TextUI\Command->main() /usr/bin/phpcpd:56
PHP 3. SebastianBergmann\FinderFacade\FinderFacade->findFiles() /usr/share/pear/SebastianBergmann/PHPCPD/TextUI/Command.php:221
PHP 4. Symfony\Component\Finder\Finder->__construct() /usr/share/pear/SebastianBergmann/FinderFacade/FinderFacade.php:93

I don't know why ? how to fix it , thank you

PMD's CPD vs. phpcpd

I've heard CPD bundled with PMD is very famous and it should support PHP. It would be nice to have a comparison of the main features and system support (one is PHP the other is Java) of phpcpd compared to that one.

not understand this

This message appear when i try to log in xml format.
phpcpd --log-pmd=pmd.xml .
The referenced parameter '--log-pmd=pmd.xml' is not registered.

I use this, under windows
with php 5.3

Glob-Style File Ignores

Support for ignoring files based on a glob pattern would be greatly desired, as such:

phpcpd --ignore *lib/vendor/* --ignore *model/om*

PHPCPD - killed automatically after 30 minutes

I've been using PHPCPD for a while now in my automated build process, but as my project kept growing, PHPCPD started taking much longer, as in exponentially. The first few times it took only a few seconds to complete, now it takes over 30 minutes and it's not even half way yet. As a result, the process get killed automatically.

I tried running the phpcpd command manually with the --progress flag, and it keeps quitting at 45.35%, which is after about 30 minutes (notice the Killed at the end of the line):

phpcpd --progress --verbose --exclude ./build/library/3rdparty ./build
phpcpd 1.4.0 by Sebastian Bergmann.

Processing files
156 / 344 [++++++++++++++++++++++++++>-------------------------------] 45.35%Killed

I understand that as a project grows, the time it takes to do the Copy/Paste detection increases, but this seems dis-proportional, especially since my entire project is only around 10.000 lines of code spread out over 350 files.

Any clue as to what is happening? I'm not 100% sure, but I have the feeling this worked fine before I upgraded to PHPCPD 1.4.0. I haven't actually downgraded, so I can't prove this atm.

System: Ubuntu 12.04 LTS
PHP 5.3.10-1ubuntu3.4 with Suhosin-Patch (cli) (built: Sep 12 2012 18:59:41)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans

phpcpd --version
phpcpd 1.4.0 by Sebastian Bergmann.

(installed via PEAR, running PEAR 1.9.4)

Update:
After a little more research I was able to nail it down to a single folder that caused the delay. Excluding this folder resulted in a 2 seconds processing time of the entire project. This particular folder might be interesting for testing and performance testing of PHPCPD. It is actually the [fonts] folder in the open source TCPDF packages: http://www.tcpdf.org/installation.php.

Any feedback is welcome!

Minimum number of tokens ignored

Using phpcpd 1.4.0 without the --min-lines or --min-tokens options I get duplication in my log file that span more than 5 (the default) lines, but less than 70 (the default) tokens. These were (correctly) ignored by phpcpd 1.3.5, so this seems like a regression to me.

Wrongly stated CLI parameters in help

The CLI help text mentions
--log-pmd
but using this format does not work. Instead, you have to use:
log-pmd=
to have the tool working correctly. This is true for all the other parameters either.

Different Results for ant target and commandline

For some reason the ant target is returning different results than the command line equivalent:

ant target:

5.97% duplicated lines out of 6634 total lines of code.

command line:

0.17% duplicated lines out of 6634 total lines of code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.