Section   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 13
c 1
b 0
f 0
dl 0
loc 47
ccs 16
cts 16
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getCommits() 0 16 4
A addCommit() 0 3 1
A isEmpty() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Vasoft\VersionIncrement\Commits;
6
7
use Vasoft\VersionIncrement\Config;
8
use Vasoft\VersionIncrement\Contract\SectionRuleInterface;
9
10
final class Section
11
{
12
    /** @var Commit[] */
13
    private array $commits = [];
14
15
    /**
16
     * @param SectionRuleInterface[] $rules
17
     */
18 29
    public function __construct(
19
        public readonly string $type,
20
        public readonly string $title,
21
        public readonly bool $hidden,
22
        public readonly array $rules,
23
        public readonly bool $isMajorMarker,
24
        public readonly bool $isMinorMarker,
25
        public readonly Config $config,
26 29
    ) {}
27
28 27
    public function addCommit(Commit $commit): void
29
    {
30 27
        $this->commits[] = $commit;
31
    }
32
33
    /**
34
     * @return Commit[]
35
     */
36 27
    public function getCommits(): array
37
    {
38 27
        if ($this->config->isHideDoubles()) {
39 1
            $result = [];
40 1
            $index = [];
41 1
            foreach ($this->commits as $commit) {
42 1
                if (!isset($index[$commit->comment])) {
43 1
                    $result[] = $commit;
44 1
                    $index[$commit->comment] = true;
45
                }
46
            }
47
48 1
            return $result;
49
        }
50
51 26
        return $this->commits;
52
    }
53
54 27
    public function isEmpty(): bool
55
    {
56 27
        return empty($this->commits);
57
    }
58
}
59