CommitCollectionFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 16
c 1
b 0
f 0
dl 0
loc 34
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollection() 0 21 3
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Vasoft\VersionIncrement\Commits;
6
7
use Vasoft\VersionIncrement\Config;
8
9
final class CommitCollectionFactory
10
{
11 27
    public function __construct(
12
        private readonly Config $config,
13
        private readonly array $majorTypes,
14
        private readonly array $minorTypes,
15
        private readonly string $defaultSection,
16 27
    ) {}
17
18
    /**
19
     * @param array $sortedSections Sorted sections array, where keys are section names and values are section
20
     *                              configurations and default section exists
21
     */
22 27
    public function getCollection(array $sortedSections): CommitCollection
23
    {
24 27
        $sections = [];
25 27
        $default = null;
26 27
        foreach ($sortedSections as $key => $section) {
27 27
            $section = new Section(
28 27
                $key,
29 27
                $section['title'],
30 27
                $section['hidden'],
31 27
                $this->config->getSectionRules($key),
32 27
                in_array($key, $this->majorTypes, true),
33 27
                in_array($key, $this->minorTypes, true),
34 27
                $this->config,
35 27
            );
36 27
            if ($this->defaultSection === $key) {
37 27
                $default = $section;
38
            }
39 27
            $sections[$key] = $section;
40
        }
41
42 27
        return new CommitCollection($sections, /* @scrutinizer ignore-type */ $default);
43
    }
44
}
45