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

systemsdk / phpcpd / #4

30 Dec 2024 04:42PM UTC coverage: 75.789%. Remained the same
#4

push

DKravtsov
phpcpd 8.0.0 release. Made codebase refactoring. Updated requirements php 8.3, updated composer dependencies, updated tests to the PHPUnit 11. Updated dev environment to the php 8.4, Phing 3.0, added code quality tools: ecs, phpstan.

271 of 379 new or added lines in 20 files covered. (71.5%)

65 existing lines in 13 files now uncovered.

648 of 855 relevant lines covered (75.79%)

2.18 hits per line

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

57.69
/src/CodeCloneMap.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Systemsdk\PhpCPD;
6

7
use Countable;
8
use IteratorAggregate;
9

10
use function count;
11
use function max;
12
use function sprintf;
13

14
final class CodeCloneMap implements Countable, IteratorAggregate
15
{
16
    /**
17
     * @var array<int, CodeClone>
18
     */
19
    private array $clones = [];
20

21
    /**
22
     * @var array<string, CodeClone>
23
     */
24
    private array $clonesById = [];
25

26
    private int $numberOfDuplicatedLines = 0;
27

28
    private int $numberOfLines = 0;
29

30
    private int $largestCloneSize = 0;
31

32
    /**
33
     * @var array<string, bool>
34
     */
35
    private array $filesWithClones = [];
36

37
    public function add(CodeClone $clone): void
38
    {
39
        $id = $clone->id();
7✔
40

41
        if (!isset($this->clonesById[$id])) {
7✔
42
            $this->clones[] = $clone;
7✔
43
            $this->clonesById[$id] = $clone;
7✔
44
        } else {
45
            $existClone = $this->clonesById[$id];
1✔
46

47
            foreach ($clone->files() as $file) {
1✔
48
                $existClone->add($file);
1✔
49
            }
50
        }
51

52
        $this->numberOfDuplicatedLines += $clone->numberOfLines() * (count($clone->files()) - 1);
7✔
53

54
        foreach ($clone->files() as $file) {
7✔
55
            if (!isset($this->filesWithClones[$file->name()])) {
7✔
56
                $this->filesWithClones[$file->name()] = true;
7✔
57
            }
58
        }
59

60
        $this->largestCloneSize = max($this->largestCloneSize, $clone->numberOfLines());
7✔
61
    }
62

63
    /**
64
     * @return array<int, CodeClone>
65
     */
66
    public function clones(): array
67
    {
68
        return $this->clones;
10✔
69
    }
70

71
    public function percentage(): string
72
    {
73
        if ($this->numberOfLines > 0) {
×
UNCOV
74
            $percent = ($this->numberOfDuplicatedLines / $this->numberOfLines) * 100;
×
75
        } else {
UNCOV
76
            $percent = 100;
×
77
        }
78

UNCOV
79
        return sprintf('%01.2F%%', $percent);
×
80
    }
81

82
    public function numberOfLines(): int
83
    {
UNCOV
84
        return $this->numberOfLines;
×
85
    }
86

87
    public function addToNumberOfLines(int $numberOfLines): void
88
    {
89
        $this->numberOfLines += $numberOfLines;
8✔
90
    }
91

92
    public function count(): int
93
    {
UNCOV
94
        return count($this->clones);
×
95
    }
96

97
    public function numberOfFilesWithClones(): int
98
    {
UNCOV
99
        return count($this->filesWithClones);
×
100
    }
101

102
    public function numberOfDuplicatedLines(): int
103
    {
UNCOV
104
        return $this->numberOfDuplicatedLines;
×
105
    }
106

107
    public function getIterator(): CodeCloneMapIterator
108
    {
109
        return new CodeCloneMapIterator($this);
1✔
110
    }
111

112
    public function isEmpty(): bool
113
    {
UNCOV
114
        return empty($this->clones);
×
115
    }
116

117
    public function averageSize(): float
118
    {
UNCOV
119
        return $this->numberOfDuplicatedLines() / $this->count();
×
120
    }
121

122
    public function largestSize(): int
123
    {
UNCOV
124
        return $this->largestCloneSize;
×
125
    }
126
}
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