XmlLibraryFactory::getBooksDependencies()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 14
rs 9.9666
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