StockTransfer   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
eloc 21
c 0
b 0
f 0
dl 0
loc 67
ccs 25
cts 25
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptions() 0 4 1
A setData() 0 8 1
A getXML() 0 8 1
A addItem() 0 16 4
A getImportRoot() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of riesenia/pohoda package.
5
 *
6
 * Licensed under the MIT License
7
 * (c) RIESENIA.com
8
 */
9
10
declare(strict_types=1);
11
12
namespace Riesenia\Pohoda;
13
14
/**
15
 * @property array{
16
 *     header: StockTransfer\Header,
17
 *     prevodkaDetail?: iterable<StockTransfer\Item>,
18
 * } $data
19
 */
20
class StockTransfer extends AbstractAgenda
21
{
22
    use Common\AddParameterToHeaderTrait;
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 4
    public function setData(array $data): parent
28
    {
29
        // pass to header
30 4
        $header = new StockTransfer\Header($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory);
31 4
        $header->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($data);
32 4
        $data = ['header' => $header];
33
34 4
        return parent::setData($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::setData($data) returns the type Riesenia\Pohoda\AbstractAgenda which is incompatible with the type-hinted return parent.
Loading history...
35
    }
36
37 1
    public function getImportRoot(): string
38
    {
39 1
        return 'lst:prevodka';
40
    }
41
42
    /**
43
     * Add item.
44
     *
45
     * @param array<string,mixed> $data
46
     *
47
     * @return $this
48
     */
49 1
    public function addItem(array $data): self
50
    {
51 1
        if (!isset($this->data['prevodkaDetail'])
52 1
            || !(
53 1
                is_array($this->data['prevodkaDetail'])
54 1
                || (is_a($this->data['prevodkaDetail'], \ArrayAccess::class))
55 1
            )
56
        ) {
57 1
            $this->data['prevodkaDetail'] = [];
58
        }
59
60 1
        $prevodkaDetail = new StockTransfer\Item($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory);
61 1
        $prevodkaDetail->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($data);
62 1
        $this->data['prevodkaDetail'][] = $prevodkaDetail;
63
64 1
        return $this;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 3
    public function getXML(): \SimpleXMLElement
71
    {
72 3
        $xml = $this->createXML()->addChild('pre:prevodka', '', $this->namespace('pre'));
73 3
        $xml->addAttribute('version', '2.0');
74
75 3
        $this->addElements($xml, ['header', 'prevodkaDetail'], 'pre');
76
77 3
        return $xml;
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
84
    {
85
        // available options
86 1
        $resolver->setDefined(['header']);
87
    }
88
}
89