• 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

96.88
/src/CodeClone.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Systemsdk\PhpCPD;
6

7
use Systemsdk\PhpCPD\Exceptions\ProcessingResultException;
8

9
use function array_map;
10
use function array_slice;
11
use function current;
12
use function file;
13
use function implode;
14
use function md5;
15

16
final class CodeClone
17
{
18
    private readonly int $numberOfLines;
19
    private readonly int $numberOfTokens;
20
    private readonly string $id;
21

22
    /**
23
     * @var array<string, CodeCloneFile>
24
     */
25
    private array $files = [];
26
    private string $lines = '';
27

28
    /**
29
     * @throws ProcessingResultException
30
     */
31
    public function __construct(CodeCloneFile $fileA, CodeCloneFile $fileB, int $numberOfLines, int $numberOfTokens)
32
    {
33
        $this->add($fileA);
7✔
34
        $this->add($fileB);
7✔
35

36
        $this->numberOfLines = $numberOfLines;
7✔
37
        $this->numberOfTokens = $numberOfTokens;
7✔
38
        $this->id = md5($this->lines());
7✔
39
    }
40

41
    public function add(CodeCloneFile $file): void
42
    {
43
        $id = $file->id();
7✔
44

45
        if (!isset($this->files[$id])) {
7✔
46
            $this->files[$id] = $file;
7✔
47
        }
48
    }
49

50
    /**
51
     * @return array<string, CodeCloneFile>
52
     */
53
    public function files(): array
54
    {
55
        return $this->files;
7✔
56
    }
57

58
    /**
59
     * @throws ProcessingResultException
60
     */
61
    public function lines(string $indent = ''): string
62
    {
63
        if (!empty($this->lines)) {
7✔
64
            return $this->lines;
2✔
65
        }
66

67
        /** @var CodeCloneFile $file */
68
        $file = current($this->files);
7✔
69
        $fileData = file($file->name());
7✔
70

71
        if ($fileData === false) {
7✔
NEW
72
            throw new ProcessingResultException('Unable to read file: ' . $file->name());
×
73
        }
74

75
        $this->lines = implode(
7✔
76
            '',
7✔
77
            array_map(
7✔
78
                static function (string $line) use ($indent) {
7✔
79
                    return $indent . $line;
7✔
80
                },
7✔
81
                array_slice(
7✔
82
                    $fileData,
7✔
83
                    $file->startLine() - 1,
7✔
84
                    $this->numberOfLines
7✔
85
                )
7✔
86
            )
7✔
87
        );
7✔
88

89
        return $this->lines;
7✔
90
    }
91

92
    public function numberOfLines(): int
93
    {
94
        return $this->numberOfLines;
7✔
95
    }
96

97
    public function numberOfTokens(): int
98
    {
99
        return $this->numberOfTokens;
3✔
100
    }
101

102
    public function id(): string
103
    {
104
        return $this->id;
7✔
105
    }
106
}
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