Completed
Push — master ( 654c5d...c6e087 )
by Dorian
02:15
created

YamlLibraryFactory::getLibraryDumper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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