Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

--min-lines, --min-tokens, and --fuzzy commandline options do not work #181

Closed
oddvalue opened this issue Feb 20, 2020 · 7 comments · Fixed by #183
Closed

--min-lines, --min-tokens, and --fuzzy commandline options do not work #181

oddvalue opened this issue Feb 20, 2020 · 7 comments · Fixed by #183
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@oddvalue
Copy link

SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection expects arguments as int but command line arguments are passed as strings.

image

@oddvalue oddvalue changed the title v5.0.0 broken in phpcd.phar v5.0.0 broken in phpcpd.phar Feb 20, 2020
@sebastianbergmann
Copy link
Owner

Please do not post screenshots but paste output as text, please.

@bambamboole
Copy link

bambamboole commented Feb 20, 2020

I am facing the very same issue.

php phpcpd.phar web/app/ --min-lines=5
 phpcpd 5.0.0 by Sebastian Bergmann.
 [20-Feb-2020 11:09:16 UTC] PHP Fatal error:  Uncaught TypeError: Argument 2 passed to SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection() must be of the type int, string given, called in phar:///builds/datapump/backend/phpcpd.phar/src/CLI/Command.php on line 140 and defined in phar:///builds/datapump/backend/phpcpd.phar/src/Detector/Detector.php:35
 Stack trace:
 #0 phar:///builds/datapump/backend/phpcpd.phar/src/CLI/Command.php(140): SebastianBergmann\PHPCPD\Detector\Detector->copyPasteDetection(Array, '5', 70, false)
 #1 phar:///builds/datapump/backend/phpcpd.phar/symfony/console/Command/Command.php(255): SebastianBergmann\PHPCPD\CLI\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
 #2 phar:///builds/datapump/backend/phpcpd.phar/symfony/console/Application.php(925): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
 #3 phar:///builds/datapump/backend/phpcpd.phar/symfo in phar:///builds/datapump/backend/phpcpd.phar/src/Detector/Detector.php on line 35
 Fatal error: Uncaught TypeError: Argument 2 passed to SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection() must be of the type int, string given, called in phar:///builds/datapump/backend/phpcpd.phar/src/CLI/Command.php on line 140 and defined in phar:///builds/datapump/backend/phpcpd.phar/src/Detector/Detector.php:35
 Stack trace:
 #0 phar:///builds/datapump/backend/phpcpd.phar/src/CLI/Command.php(140): SebastianBergmann\PHPCPD\Detector\Detector->copyPasteDetection(Array, '5', 70, false)
 #1 phar:///builds/datapump/backend/phpcpd.phar/symfony/console/Command/Command.php(255): SebastianBergmann\PHPCPD\CLI\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
 #2 phar:///builds/datapump/backend/phpcpd.phar/symfony/console/Application.php(925): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
 #3 phar:///builds/datapump/backend/phpcpd.phar/symfo in phar:///builds/datapump/backend/phpcpd.phar/src/Detector/Detector.php on line 35
 ERROR: Job failed: exit code 1

Did the API changed with v 5.0.0 ?

@sebastianbergmann
Copy link
Owner

I cannot reproduce the issue:

$ wget https://phar.phpunit.de/phpcpd.phar      
$ php phpcpd.phar /usr/local/src/phpunit
phpcpd 5.0.0 by Sebastian Bergmann.

Found 14 clones with 597 duplicated lines in 21 files:

  - /usr/local/src/phpunit/vendor/sebastian/diff/src/Output/StrictUnifiedDiffOutputBuilder.php:117-226 (109 lines)
    /usr/local/src/phpunit/vendor/sebastian/diff/src/Output/UnifiedDiffOutputBuilder.php:67-176

  - /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php:44-106 (62 lines)
    /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyRead.php:44-106

  - /usr/local/src/phpunit/vendor/sebastian/diff/src/Output/StrictUnifiedDiffOutputBuilder.php:230-284 (54 lines)
    /usr/local/src/phpunit/vendor/sebastian/diff/src/Output/UnifiedDiffOutputBuilder.php:178-232

  - /usr/local/src/phpunit/vendor/sebastian/comparator/tests/MockObjectComparatorTest.php:117-165 (48 lines)
    /usr/local/src/phpunit/vendor/sebastian/comparator/tests/ObjectComparatorTest.php:101-149

  - /usr/local/src/phpunit/tests/unit/Framework/AssertTest.php:2320-2362 (42 lines)
    /usr/local/src/phpunit/vendor/sebastian/comparator/tests/DateTimeComparatorTest.php:107-149

  - /usr/local/src/phpunit/vendor/sebastian/comparator/tests/DoubleComparatorTest.php:93-134 (41 lines)
    /usr/local/src/phpunit/vendor/sebastian/comparator/tests/NumericComparatorTest.php:82-123

  - /usr/local/src/phpunit/tests/_files/BankAccountTest.php:17-57 (40 lines)
    /usr/local/src/phpunit/tests/_files/BankAccountTest2.php:15-55

  - /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php:65-104 (39 lines)
    /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Var_.php:66-105

  - /usr/local/src/phpunit/src/Framework/TestListener.php:22-59 (37 lines)
    /usr/local/src/phpunit/src/Framework/TestListenerDefaultImplementation.php:17-54

  - /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php:44-77 (33 lines)
    /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyWrite.php:44-77

  - /usr/local/src/phpunit/vendor/sebastian/diff/tests/Output/Integration/StrictUnifiedDiffOutputBuilderIntegrationTest.php:249-278 (29 lines)
    /usr/local/src/phpunit/vendor/sebastian/diff/tests/Output/Integration/UnifiedDiffOutputBuilderIntegrationTest.php:84-113

  - /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Property.php:77-106 (29 lines)
    /usr/local/src/phpunit/vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/PropertyWrite.php:77-106

  - /usr/local/src/phpunit/tests/_files/DataProviderDebugTest.php:16-38 (22 lines)
    /usr/local/src/phpunit/vendor/sebastian/exporter/tests/ExporterTest.php:32-54

  - /usr/local/src/phpunit/tests/unit/Util/ConfigurationTest.php:604-616 (12 lines)
    /usr/local/src/phpunit/tests/unit/Util/ConfigurationTest.php:624-636

0.48% duplicated lines out of 123665 total lines of code.
Average size of duplication is 42 lines, largest clone has 109 of lines

Time: 528 ms, Memory: 74.00 MB

What am I missing?

@bambamboole
Copy link

bambamboole commented Feb 20, 2020

Update:
This does not fail with PHP 7.2 but fails with PHP 7.4

Output with PHP7.2: (it is not compatible as I just realized :-D)

➜  datapump git:(xxx) ✗ php -v
PHP 7.2.9 (cli) (built: Aug 21 2018 07:42:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.9, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.1, Copyright (c) 2002-2018, by Derick Rethans
➜  datapump git:(xxx) ✗ php phpcpd.phar web/app --min-lines=5
This version of PHPCPD requires PHP 7.3 (or later).
You are using PHP 7.2.9 (/usr/local/php5-7.2.9-20180821-074958/bin/php).

Output with PHP 7.4:

root@d83d4b4b6eae:/app# php -v
PHP 7.4.2 (cli) (built: Jan 24 2020 06:56:01) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies
root@d83d4b4b6eae:/app# php phpcpd.phar web/app/ --min-lines=5
phpcpd 5.0.0 by Sebastian Bergmann.

[20-Feb-2020 11:48:40 UTC] PHP Fatal error:  Uncaught TypeError: Argument 2 passed to SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection() must be of the type int, string given, called in phar:///app/phpcpd.phar/src/CLI/Command.php on line 140 and defined in phar:///app/phpcpd.phar/src/Detector/Detector.php:35
Stack trace:
#0 phar:///app/phpcpd.phar/src/CLI/Command.php(140): SebastianBergmann\PHPCPD\Detector\Detector->copyPasteDetection(Array, '5', 70, false)
#1 phar:///app/phpcpd.phar/symfony/console/Command/Command.php(255): SebastianBergmann\PHPCPD\CLI\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 phar:///app/phpcpd.phar/symfony/console/Application.php(925): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///app/phpcpd.phar/symfony/console/Application.php(265): Symfony\Component\Console\Application->doRunCommand(Object(SebastianBergmann\PHPCPD\CLI in phar:///app/phpcpd.phar/src/Detector/Detector.php on line 35

Fatal error: Uncaught TypeError: Argument 2 passed to SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection() must be of the type int, string given, called in phar:///app/phpcpd.phar/src/CLI/Command.php on line 140 and defined in phar:///app/phpcpd.phar/src/Detector/Detector.php:35
Stack trace:
#0 phar:///app/phpcpd.phar/src/CLI/Command.php(140): SebastianBergmann\PHPCPD\Detector\Detector->copyPasteDetection(Array, '5', 70, false)
#1 phar:///app/phpcpd.phar/symfony/console/Command/Command.php(255): SebastianBergmann\PHPCPD\CLI\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#2 phar:///app/phpcpd.phar/symfony/console/Application.php(925): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#3 phar:///app/phpcpd.phar/symfony/console/Application.php(265): Symfony\Component\Console\Application->doRunCommand(Object(SebastianBergmann\PHPCPD\CLI in phar:///app/phpcpd.phar/src/Detector/Detector.php on line 35

@sebastianbergmann
Copy link
Owner

PHP 7.2 is dead (at least to me). PHPCPD 5 is not supported on PHP 7.2. I cannot reproduce this with PHP 7.4.

@sebastianbergmann sebastianbergmann self-assigned this Feb 20, 2020
@sebastianbergmann sebastianbergmann added the bug Indicates an unexpected problem or unintended behavior label Feb 20, 2020
sebastianbergmann pushed a commit that referenced this issue Feb 20, 2020
Will fix #181 
Though Im not sure if it is the correct method.
But as symfony ArgvInput is missing type casting, I think this is the only way to fix it
@RSpeekenbrink
Copy link

Same issue on PHP 7.3 gitlab runner:

 $ php phpcpd.phar app/ --min-lines=50
 phpcpd 5.0.0 by Sebastian Bergmann.
 Fatal error: Uncaught TypeError: Argument 2 passed to SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection() must be of the type int, string given, called in phar:///builds/company/product/phpcpd.phar/src/CLI/Command.php on line 140 and defined in phar:///builds/company/product/phpcpd.phar/src/Detector/Detector.php:35
 Stack trace:
 #0 phar:///builds/company/product/phpcpd.phar/src/CLI/Command.php(140): SebastianBergmann\PHPCPD\Detector\Detector->copyPasteDetection(Array, '50', 70, false)
 #1 phar:///builds/company/product/phpcpd.phar/symfony/console/Command/Command.php(255): SebastianBergmann\PHPCPD\CLI\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
 #2 phar:///builds/company/product/phpcpd.phar/symfony/console/Application.php(925): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
 #3 phar:///builds/company/product/phpcpd.phar/symf in phar:///builds/company/product/phpcpd.phar/src/Detector/Detector.php on line 35

@lsv
Copy link
Contributor

lsv commented Feb 20, 2020

@sebastianbergmann you need to add --min-lines=10 to your command.

As described in my PR - when you type something in the command, it will be added as a string, as there are no type casting in ArgvInput

@sebastianbergmann sebastianbergmann changed the title v5.0.0 broken in phpcpd.phar --min-lines, --min-tokens, and --fuzzy commandline options do not work Feb 20, 2020
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants