Section::getCommits()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.9666
cc 4
nc 4
nop 0
crap 4
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