StockTransfer::configureOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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->dependenciesFactory);
31 4
        $header
32 4
            ->setDirectionalVariable($this->useOneDirectionalVariables)
33 4
            ->setResolveOptions($this->resolveOptions)
34 4
            ->setData($data);
35 4
        $data = ['header' => $header];
36
37 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...
38
    }
39
40 1
    public function getImportRoot(): string
41
    {
42 1
        return 'lst:prevodka';
43
    }
44
45
    /**
46
     * Add item.
47
     *
48
     * @param array<string,mixed> $data
49
     *
50
     * @return $this
51
     */
52 1
    public function addItem(array $data): self
53
    {
54 1
        if (!isset($this->data['prevodkaDetail'])
55 1
            || !(
56 1
                is_array($this->data['prevodkaDetail'])
57 1
                || (is_a($this->data['prevodkaDetail'], \ArrayAccess::class))
58 1
            )
59
        ) {
60 1
            $this->data['prevodkaDetail'] = [];
61
        }
62
63 1
        $prevodkaDetail = new StockTransfer\Item($this->dependenciesFactory);
64 1
        $prevodkaDetail
65 1
            ->setDirectionalVariable($this->useOneDirectionalVariables)
66 1
            ->setResolveOptions($this->resolveOptions)
67 1
            ->setData($data);
68 1
        $this->data['prevodkaDetail'][] = $prevodkaDetail;
69
70 1
        return $this;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 3
    public function getXML(): \SimpleXMLElement
77
    {
78 3
        $xml = $this->createXML()->addChild('pre:prevodka', '', $this->namespace('pre'));
79 3
        $xml->addAttribute('version', '2.0');
80
81 3
        $this->addElements($xml, ['header', 'prevodkaDetail'], 'pre');
82
83 3
        return $xml;
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
90
    {
91
        // available options
92 1
        $resolver->setDefined(['header']);
93
    }
94
}
95