DefaultChangelogFactory::createStatusCollection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Changelog;
6
7
use DateTimeImmutable;
8
use function array_map;
9
10
final class DefaultChangelogFactory implements ChangelogFactory
11
{
12
    /** @inheritDoc */
13 3
    public function create(array $data): Changelog
14
    {
15 3
        return new DefaultChangelog(
16 3
            $data['version'],
17 3
            new DateTimeImmutable($data['date']),
18 3
            $this->createStatusCollection($data),
19 3
        );
20
    }
21
22
    /** @inheritDoc */
23 3
    public function createCollection(array $data): ChangelogCollection
24
    {
25 3
        return new DefaultChangelogCollection(
26 3
            array_map(fn (array $version): Changelog => $this->create($version), $data['versions']),
27 3
        );
28
    }
29
30
    /**
31
     * @param array<string,mixed> $data
32
     */
33 3
    private function createStatus(array $data): ChangelogStatus
34
    {
35 3
        return new DefaultChangelogStatus(
36 3
            $data['name'],
37 3
            $data['description'],
38 3
        );
39
    }
40
41
    /**
42
     * @param array<string,mixed> $data
43
     */
44 3
    private function createStatusCollection(array $data): ChangelogStatusCollection
45
    {
46 3
        return new DefaultChangelogStatusCollection(
47 3
            array_map(fn (array $change): ChangelogStatus => $this->createStatus($change), $data['changes']),
48 3
        );
49
    }
50
}
51