AbstractItem::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\Document;
13
14
use Riesenia\Pohoda\Common;
15
use Riesenia\Pohoda\Type;
16
17
/**
18
 * @property array{
19
 *     parameters?: iterable<Type\Parameter>,
20
 *     homeCurrency?: Type\CurrencyItem,
21
 *     foreignCurrency?: Type\CurrencyItem,
22
 *     stockItem?: Type\StockItem,
23
 * } $data
24
 */
25
abstract class AbstractItem extends AbstractPart
26
{
27
    use Common\AddParameterTrait;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 16
    public function setData(array $data): parent
33
    {
34
        // process home currency
35 16
        if (isset($data['homeCurrency'])) {
36 12
            $homeCurrency = new Type\CurrencyItem($this->dependenciesFactory);
37 12
            $homeCurrency
38 12
                ->setDirectionalVariable($this->useOneDirectionalVariables)
39 12
                ->setResolveOptions($this->resolveOptions)
40 12
                ->setData($data['homeCurrency']);
41 12
            $data['homeCurrency'] = $homeCurrency;
42
        }
43
44
        // process foreign currency
45 16
        if (isset($data['foreignCurrency'])) {
46 1
            $foreignCurrency = new Type\CurrencyItem($this->dependenciesFactory);
47 1
            $foreignCurrency
48 1
                ->setDirectionalVariable($this->useOneDirectionalVariables)
49 1
                ->setResolveOptions($this->resolveOptions)
50 1
                ->setData($data['foreignCurrency']);
51 1
            $data['foreignCurrency'] = $foreignCurrency;
52
        }
53
54
        // process stock item
55 16
        if (isset($data['stockItem'])) {
56 7
            $stockItem = new Type\StockItem($this->dependenciesFactory);
57 7
            $stockItem
58 7
                ->setDirectionalVariable($this->useOneDirectionalVariables)
59 7
                ->setResolveOptions($this->resolveOptions)
60 7
                ->setData($data['stockItem']);
61 7
            $data['stockItem'] = $stockItem;
62
        }
63
64 16
        return parent::setData($data);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::setData($data) returns the type Riesenia\Pohoda\Document\AbstractPart which is incompatible with the type-hinted return parent.
Loading history...
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 14
    public function getXML(): \SimpleXMLElement
71
    {
72 14
        if (is_null($this->namespace)) {
73 1
            throw new \LogicException('Namespace not set.');
74
        }
75
76 13
        if (is_null($this->nodePrefix)) {
77 1
            throw new \LogicException('Node name prefix not set.');
78
        }
79
80 12
        $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Item', '', $this->namespace($this->namespace));
81
82 12
        $this->addElements($xml, \array_merge($this->elements, ['parameters']), $this->namespace);
83
84 12
        return $xml;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 9
    protected function configureOptions(Common\OptionsResolver $resolver): void
91
    {
92
        // available options
93 9
        $resolver->setDefined($this->elements);
94
    }
95
}
96