Storage   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
eloc 18
dl 0
loc 67
c 0
b 0
f 0
ccs 22
cts 22
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addSubStorage() 0 5 1
A getDefaultDto() 0 3 1
A getXML() 0 8 1
A getImportRoot() 0 3 1
A storageXML() 0 15 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace kalanis\Pohoda;
6
7
/**
8
 * @property Storage\StorageDto $data
9
 */
10
class Storage extends AbstractAgenda
11
{
12 1
    public function getImportRoot(): string
13
    {
14 1
        return 'lst:itemStorage';
15
    }
16
17
    /**
18
     * Add sub storage.
19
     *
20
     * @param self $storage
21
     *
22
     * @return $this
23
     */
24 1
    public function addSubStorage(self $storage): self
25
    {
26 1
        $this->data->subStorages[] = $storage;
27
28 1
        return $this;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 2
    public function getXML(): \SimpleXMLElement
35
    {
36 2
        $xml = $this->createXML()->addChild('str:storage', '', $this->namespace('str'));
37 2
        $xml->addAttribute('version', '2.0');
38
39 2
        $this->storageXML($xml);
40
41 2
        return $xml;
42
    }
43
44
    /**
45
     * Attach storage to XML element.
46
     *
47
     * @param \SimpleXMLElement $xml
48
     *
49
     * @return void
50
     */
51 2
    public function storageXML(\SimpleXMLElement $xml): void
52
    {
53 2
        $storage = $xml->addChild('str:itemStorage', '', $this->namespace('str'));
54 2
        $storage->addAttribute('code', \strval($this->data->code));
55
56 2
        if (isset($this->data->name)) {
57 1
            $storage->addAttribute('name', \strval($this->data->name));
58
        }
59
60 2
        if (!empty($this->data->subStorages)) {
61 1
            $subStorages = $storage->addChild('str:subStorages', '', $this->namespace('str'));
62
63 1
            foreach ($this->data->subStorages as $subStorage) {
64 1
                if (\is_a($subStorage, self::class)) {
65 1
                    $subStorage->storageXML($subStorages);
66
                }
67
            }
68
        }
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 3
    protected function getDefaultDto(): Common\Dtos\AbstractDto
75
    {
76 3
        return new Storage\StorageDto();
77
    }
78
}
79