StockItem::setData()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
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\Stock;
13
14
use Riesenia\Pohoda\AbstractAgenda;
15
use Riesenia\Pohoda\Common;
16
17
class StockItem extends AbstractAgenda
18
{
19
    /** @var string[] */
20
    protected array $refElements = ['stockInfo', 'storage'];
21
22
    /** @var string[] */
23
    protected array $elements = ['id', 'stockInfo', 'storage', 'code', 'name', 'count', 'quantity', 'stockPriceItem'];
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 1
    public function setData(array $data): parent
29
    {
30
        // process stockPriceItem
31 1
        if (isset($data['stockPriceItem']) && is_array($data['stockPriceItem'])) {
32 1
            $data['stockPriceItem'] = \array_map(function ($stockPriceItem) {
33 1
                $price = new Price($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory);
34 1
                return $price->setDirectionalVariable($this->useOneDirectionalVariables)->setData($stockPriceItem['stockPrice']);
35 1
            }, $data['stockPriceItem']);
36
        }
37
38 1
        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...
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function getXML(): \SimpleXMLElement
45
    {
46 1
        $xml = $this->createXML()->addChild('stk:stockItem', '', $this->namespace('stk'));
47
48 1
        $this->addElements($xml, $this->elements, 'stk');
49
50 1
        return $xml;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
57
    {
58
        // available options
59 1
        $resolver->setDefined($this->elements);
60
61 1
        $resolver->setNormalizer('id', $this->normalizerFactory->getClosure('int'));
62 1
        $resolver->setNormalizer('count', $this->normalizerFactory->getClosure('float'));
63 1
        $resolver->setNormalizer('quantity', $this->normalizerFactory->getClosure('float'));
64
    }
65
}
66