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 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f0a93b7
Add files for suffix tree algorithm
olleharstedt Jun 17, 2021
0179eff
Add new command argument: algorithm
olleharstedt Jun 17, 2021
8d3c0cb
Report clone properly
olleharstedt Jun 17, 2021
4224ba3
Remove unused code
olleharstedt Jun 17, 2021
f2dd32a
Free tokens memory
olleharstedt Jun 17, 2021
093a8d0
Add post-process step, so suffixtree algo can collect all tokens first
olleharstedt Jun 17, 2021
793d486
Add algorithm setting to help text
olleharstedt Jun 17, 2021
12279b4
Add description of the rabin karp algorithm
olleharstedt Jun 17, 2021
c9e22de
Move hashes from abstract strategy
olleharstedt Jun 22, 2021
af01d9e
Factor out strategy configuration DTO
olleharstedt Jun 22, 2021
d2e1429
Remove test file
olleharstedt Jun 22, 2021
c2acc9e
Add missing file
olleharstedt Jun 22, 2021
65f22c7
Remove duplicated method; fix argument access
olleharstedt Jun 22, 2021
f060ac3
Indentation
olleharstedt Jun 22, 2021
eaae196
Testing
olleharstedt Jun 22, 2021
c8625c8
Check if we fetch sentinel by mistake
olleharstedt Jun 22, 2021
7142b7b
Apply cs-fixer
olleharstedt Jun 23, 2021
eea6450
Psalm fixes (WIP)
olleharstedt Jun 23, 2021
e24e902
Psalm fixes (WIP)
olleharstedt Jun 23, 2021
fe9e37b
Replace JavaObjectInterface with AbstractToken
olleharstedt Jun 24, 2021
6775c1d
Make it run
olleharstedt Jun 24, 2021
197cde3
Psalm fixes, done
olleharstedt Jun 24, 2021
893dbfd
Run cs-fix
olleharstedt Jun 24, 2021
75d1e22
Phpunit (WIP)
olleharstedt Jun 26, 2021
873a934
Psalm + cs fix
olleharstedt Jun 26, 2021
44b9df9
Some small notes
olleharstedt Jun 26, 2021
bbb3203
Apply cs fix
olleharstedt Jun 26, 2021
33a3b95
Add cover annotations to tests
olleharstedt Jun 30, 2021
6231b93
Apply cs fix
olleharstedt Jul 20, 2021
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
Prev Previous commit
Next Next commit
Report clone properly
  • Loading branch information
olleharstedt committed Jun 17, 2021
commit 8d3c0cb81fcf4b496a50682dab9cd53f9a18a35a
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public function findClones(int $minLength, int $maxErrors, int $headEquality)
}
}

$map = [];

for ($index = 0; $index <= count($this->word); ++$index) {
$existingClones = $this->cloneInfos[$index] ?? null;
if ($existingClones != null) {
Expand Down
28 changes: 16 additions & 12 deletions src/Detector/Strategy/SuffixTreeStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
use function array_keys;
use function file_get_contents;
use function token_get_all;
use SebastianBergmann\PHPCPD\Detector\Strategy\SuffixTree\ApproximateCloneDetectingSuffixTree;
use SebastianBergmann\PHPCPD\Detector\Strategy\SuffixTree\PhpToken;
use SebastianBergmann\PHPCPD\Detector\Strategy\SuffixTree\CloneInfo;
use SebastianBergmann\PHPCPD\CodeClone;
use SebastianBergmann\PHPCPD\CodeCloneFile;
use SebastianBergmann\PHPCPD\CodeCloneMap;

final class SuffixTreeStrategy extends AbstractStrategy
{
Expand All @@ -40,14 +44,14 @@ public function processFile(string $file, int $minLines, int $minTokens, CodeClo
}
}
$tree = new ApproximateCloneDetectingSuffixTree($word);
$editDistance = 5;
$editDistance = 10;
$headEquality = 10;
/** @var CloneInfo[] */
$cloneInfos = $tree->findClones($minTokens, $editDistance, $headEquality);

foreach ($cloneInfos as $cloneInfo) {
/** @var PhpToken */
$lastToken = $this->word[$cloneInfo->position + $cloneInfo->length];
$lastToken = $word[$cloneInfo->position + $cloneInfo->length];
$lines = $lastToken->line - $cloneInfo->token->line;
/*
printf(
Expand All @@ -58,23 +62,23 @@ public function processFile(string $file, int $minLines, int $minTokens, CodeClo
$lines
);
*/
$result->add(
new CodeClone(
new CodeCloneFile($cloneInfo->token->file, $cloneInfo->token->line),
new CodeCloneFile($t->file, $t->line),
$lines,
0
)
);
/** @var int[] */
$others = $cloneInfo->otherClones->extractFirstList();
for ($j = 0; $j < count($others); $j++) {
$otherStart = $others[$j];
/** @var PhpToken */
$t = $this->word[$otherStart];
$t = $word[$otherStart];
/** @var PhpToken */
$lastToken = $this->word[$cloneInfo->position + $cloneInfo->length];
$lastToken = $word[$cloneInfo->position + $cloneInfo->length];
$lines = $lastToken->line - $cloneInfo->token->line;
$result->add(
new CodeClone(
new CodeCloneFile($cloneInfo->token->file, $cloneInfo->token->line),
new CodeCloneFile($t->file, $t->line),
$lines,
0
)
);
/*
printf(
" %s:%d-%d\n",
Expand Down