buildChronologicalMarkerDependencies()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gnutix\StarWarsLibrary\LibraryFactory;
6
7
use Gnutix\Library\LibraryFactory\YamlLibraryFactory as BaseYamlLibraryFactory;
8
use Gnutix\StarWarsLibrary\Dumper\YamlLibraryDumper;
9
use Gnutix\StarWarsLibrary\Model\Library;
10
11
/**
12
 * @method Library getLibrary()
13
 */
14
final class YamlLibraryFactory extends BaseYamlLibraryFactory
15
{
16
    public function getLibraryDumper(): YamlLibraryDumper
17
    {
18
        return new YamlLibraryDumper();
19
    }
20
21
    protected function getLibraryDependencies(array $data): array
22
    {
23
        return array_merge(
24
            parent::getLibraryDependencies($data),
25
            [
26
                'eras' => $this->buildClassInstanceFromArray($data['eras'], 'era'),
27
            ]
28
        );
29
    }
30
31
    protected function getBookDependencies(array $book): array
32
    {
33
        $starWarsNode = $this->get($book, 'starWars', []);
34
35
        return array_merge(
36
            parent::getBookDependencies($book),
37
            [
38
                'chronologicalMarker' => new $this->classes['chronologicalMarker'](
39
                    $this->buildChronologicalMarkerDependencies($this->get($starWarsNode, 'chronology', []))
40
                ),
41
                'swuBookId' => $this->get($starWarsNode, 'swuBookId'),
42
            ]
43
        );
44
    }
45
46
    protected function buildChronologicalMarkerDependencies(array $chronologicalMarker): array
47
    {
48
        $timeEnd = null;
49
        $timeStart = $time = $this->get($chronologicalMarker, 'time');
50
        if (is_array($time)) {
51
            $timeStart = $this->get($time, 'start');
52
            $timeEnd = $this->get($time, 'end');
53
        }
54
55
        return [
56
            'timeStart' => $timeStart,
57
            'timeEnd' => $timeEnd,
58
            'era' => new $this->classes['era']($this->get($chronologicalMarker, 'era', [])),
59
        ];
60
    }
61
}
62