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

XmlLibraryFactory::getBooksDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 16
rs 9.4285
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
namespace Gnutix\StarWarsLibrary\LibraryFactory;
4
5
use Gnutix\Library\LibraryFactory\XmlLibraryFactory as BaseXmlLibraryFactory;
6
use Gnutix\StarWarsLibrary\Model\Library;
7
8
/**
9
 * Library Factory for the XML data
10
 *
11
 * @method Library getLibrary()    This allows the auto-completion to work correctly
12
 */
13
class XmlLibraryFactory extends BaseXmlLibraryFactory
14
{
15
    /**
16
     * {@inheritDoc}
17
     */
18
    protected function getLibraryDependencies(\SimpleXMLElement $data)
19
    {
20
        return array_merge(
21
            parent::getLibraryDependencies($data),
22
            array(
23
                'eras' => $this->buildClassInstanceFromNodeAttributes($data, '//books/era', 'era'),
24
            )
25
        );
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    protected function getBooksDependencies(\SimpleXMLElement $data, \SimpleXMLElement $book)
32
    {
33
        $era = $book->xpath('parent::era');
34
35
        return array_merge(
36
            parent::getBooksDependencies($data, $book),
37
            array(
38
                'chronologicalMarker' => new $this->classes['chronologicalMarker'](
39
                    array(
40
                        'timeStart' => (string) $book->{'time'},
41
                        'era' => new $this->classes['era']($this->getSimpleXmlElementAttributesAsArray(reset($era))),
42
                    )
43
                )
44
            )
45
        );
46
    }
47
}
48