XmlLibraryFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 13
c 2
b 0
f 0
dl 0
loc 26
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBooksDependencies() 0 14 1
A getLibraryDependencies() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gnutix\StarWarsLibrary\LibraryFactory;
6
7
use Gnutix\Library\LibraryFactory\XmlLibraryFactory as BaseXmlLibraryFactory;
8
use Gnutix\StarWarsLibrary\Model\Library;
9
use SimpleXMLElement;
10
use Webmozart\Assert\Assert;
11
12
/**
13
 * @method Library getLibrary()
14
 */
15
final class XmlLibraryFactory extends BaseXmlLibraryFactory
16
{
17
    protected function getLibraryDependencies(SimpleXMLElement $data): array
18
    {
19
        return array_merge(
20
            parent::getLibraryDependencies($data),
21
            [
22
                'eras' => $this->buildClassInstanceFromNodeAttributes($data, '//books/era', 'era'),
23
            ]
24
        );
25
    }
26
27
    protected function getBooksDependencies(SimpleXMLElement $data, SimpleXMLElement $book): array
28
    {
29
        $eras = $book->xpath('parent::era');
30
        Assert::isIterable($eras);
31
        $era = reset($eras);
32
        Assert::isInstanceOf($era, SimpleXMLElement::class);
33
34
        return array_merge(
35
            parent::getBooksDependencies($data, $book),
36
            [
37
                'chronologicalMarker' => new $this->classes['chronologicalMarker'](
38
                    [
39
                        'timeStart' => (string) $book->{'time'},
40
                        'era' => new $this->classes['era']($this->getSimpleXmlElementAttributesAsArray($era)),
41
                    ]
42
                ),
43
            ]
44
        );
45
    }
46
}
47