Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@
"branch-alias": {
"dev-master": "4.0-dev"
}
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project does not use PHPUnit installed via Composer.

"require-dev": {
"phpunit/phpunit": "^7.3"
}
}
3 changes: 3 additions & 0 deletions src/Detector/Strategy/DefaultStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public function processFile(string $file, int $minLines, int $minTokens, CodeClo
foreach (\array_keys($tokens) as $key) {
$token = $tokens[$key];

if (is_string($token) && $token === '?') {
$token = [0, '?', $lastTokenLine];
}
if (\is_array($token)) {
if (!isset($this->tokensIgnoreList[$token[0]])) {
if ($tokenNr === 0) {
Expand Down
23 changes: 22 additions & 1 deletion tests/DetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testDetectingSimpleClonesWorks($strategy): void
$this->assertEquals(TEST_FILES_PATH . 'Math.php', $file->getName());
$this->assertEquals(139, $file->getStartLine());
$this->assertEquals(59, $clones[0]->getSize());
$this->assertEquals(136, $clones[0]->getTokens());
$this->assertEquals(138, $clones[0]->getTokens());

$this->assertEquals(
' public function div($v1, $v2)
Expand Down Expand Up @@ -288,6 +288,27 @@ public function testStripComments($strategy): void
$this->assertCount(1, $clones);
}

/**
* @covers SebastianBergmann\PHPCPD\Detector\Detector::copyPasteDetection
* @dataProvider strategyProvider
*
* @param string $strategy
*/
public function testNullableTypeHints(string $strategy): void
{
$detector = new SebastianBergmann\PHPCPD\Detector\Detector(new $strategy);
$clones = $detector->copyPasteDetection(
[
TEST_FILES_PATH . 'NullableTypeHint.php',
],
2,
7,
true
);
$clones = $clones->getClones();
$this->assertCount(0, $clones);
}

public function strategyProvider()
{
return [
Expand Down
17 changes: 17 additions & 0 deletions tests/_files/NullableTypeHint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

class NullableTypeHintA
{
function foo(?string $foo): ?string
{
return $foo;
}
}

class NullableTypeHintB
{
function foo(string $foo): string
{
return $foo;
}
}