• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemsdk / phpcpd / #6

23 Mar 2025 04:51PM UTC coverage: 75.711% (-0.08%) from 75.789%
#6

push

DKravtsov
phpcpd 8.1.0 release. Added Suffix Tree-based algorithm for code clone detection (experimental), added progress bar. Made codebase refactoring. Updated packages: sebastian/cli-parser, sebastian/version, phpunit/php-file-iterator, phpunit/php-timer. Updated tests to the PHPUnit 12.

101 of 126 new or added lines in 10 files covered. (80.16%)

1 existing line in 1 file now uncovered.

692 of 914 relevant lines covered (75.71%)

3.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.43
/src/Detector/Detector.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Systemsdk\PhpCPD\Detector;
6

7
use Systemsdk\PhpCPD\CodeCloneMap;
8
use Systemsdk\PhpCPD\Detector\Strategy\AbstractStrategy;
9
use Systemsdk\PhpCPD\Exceptions\ProcessingResultException;
10

11
use function sprintf;
12

13
final class Detector
14
{
15
    public function __construct(
16
        private readonly AbstractStrategy $strategy,
17
        private readonly bool $useProgressBar = false
18
    ) {
19
    }
12✔
20

21
    /**
22
     * @param array<int, string> $files
23
     *
24
     * @throws ProcessingResultException
25
     */
26
    public function copyPasteDetection(array $files): CodeCloneMap
27
    {
28
        $result = new CodeCloneMap();
12✔
29
        $totalItems = count($files);
12✔
30
        $processedFiles = 0;
12✔
31
        foreach ($files as $file) {
12✔
32
            $processedFiles++;
12✔
33

34
            if (empty($file)) {
12✔
NEW
35
                $this->progressBar($processedFiles, $totalItems);
×
36

UNCOV
37
                continue;
×
38
            }
39

40
            $this->strategy->processFile($file, $result);
12✔
41
            $this->progressBar($processedFiles, $totalItems);
12✔
42
        }
43
        $this->strategy->postProcess();
12✔
44

45
        return $result;
12✔
46
    }
47

48
    private function progressBar(int $done, int $total, string $title = '', int $width = 30): void
49
    {
50
        if ($this->useProgressBar === false) {
12✔
51
            return;
12✔
52
        }
53

NEW
54
        $perc = (int)floor(($done * 100) / $total);
×
NEW
55
        $bar = (int)floor(($width * $perc) / 100);
×
56

NEW
57
        print sprintf(
×
NEW
58
            " %s/%s [%s>%s] %s%% %s\r",
×
NEW
59
            $done,
×
NEW
60
            $total,
×
NEW
61
            str_repeat('=', $bar),
×
NEW
62
            str_repeat(' ', $width - $bar),
×
NEW
63
            $perc,
×
NEW
64
            $title
×
NEW
65
        );
×
66

NEW
67
        if ($done >= $total) {
×
NEW
68
            print PHP_EOL;
×
69
        }
70
    }
71
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc