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

systemsdk / phpcpd / #23

18 May 2025 05:01PM UTC coverage: 75.818% (-0.7%) from 76.552%
#23

push

DKravtsov
phpcpd 8.2.2 release. Improved progress bar.

9 of 34 new or added lines in 3 files covered. (26.47%)

718 of 947 relevant lines covered (75.82%)

3.61 hits per line

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

60.0
/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\Detector\Strategy\SuffixTreeStrategy;
10
use Systemsdk\PhpCPD\Detector\Traits\ProgressBarTrait;
11
use Systemsdk\PhpCPD\Exceptions\ProcessingResultException;
12

13
final class Detector
14
{
15
    use ProgressBarTrait;
16

17
    private const int PROGRESS_BAR_BOUNDARY = 20;
18
    private const string PROGRESS_BAR_RABIN_KARP_TITLE = 'Loading & Processing';
19
    private const string PROGRESS_BAR_SUFFIX_TREE_TITLE = 'Loading';
20

21
    public function __construct(
22
        private readonly AbstractStrategy $strategy,
23
        private readonly bool $useProgressBar = false
24
    ) {
25
    }
12✔
26

27
    /**
28
     * @param array<int, string> $files
29
     *
30
     * @throws ProcessingResultException
31
     */
32
    public function copyPasteDetection(array $files): CodeCloneMap
33
    {
34
        $result = new CodeCloneMap();
12✔
35
        $totalItems = count($files);
12✔
36
        $processedFiles = 0;
12✔
37
        $boundary = self::PROGRESS_BAR_BOUNDARY;
12✔
38
        foreach ($files as $file) {
12✔
39
            $processedFiles++;
12✔
40

41
            if (!empty($file)) {
12✔
42
                $this->strategy->processFile($file, $result);
12✔
43
            }
44

45
            if ($this->useProgressBar && $this->countProgressBarPercent($processedFiles, $totalItems) >= $boundary) {
12✔
NEW
46
                $this->progressBar(
×
NEW
47
                    $processedFiles,
×
NEW
48
                    $totalItems,
×
NEW
49
                    $this->strategy instanceof SuffixTreeStrategy
×
NEW
50
                        ? self::PROGRESS_BAR_SUFFIX_TREE_TITLE
×
NEW
51
                        : self::PROGRESS_BAR_RABIN_KARP_TITLE
×
NEW
52
                );
×
NEW
53
                $boundary += self::PROGRESS_BAR_BOUNDARY;
×
54
            }
55
        }
56
        $this->strategy->postProcess($this->useProgressBar);
12✔
57

58
        return $result;
12✔
59
    }
60
}
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