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

XmlLibraryFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 7
Bugs 0 Features 2
Metric Value
wmc 2
c 7
b 0
f 2
lcom 1
cbo 1
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLibraryDependencies() 0 9 1
A getBooksDependencies() 0 16 1
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