Issues (28)

src/Pohoda/Document/AbstractItem.php (1 issue)

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
abstract class AbstractItem extends AbstractPart
18
{
19
    use Common\AddParameterTrait;
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 16
    public function setData(array $data): parent
25
    {
26
        // process home currency
27 16
        if (isset($data['homeCurrency'])) {
28 12
            $homeCurrency = new Type\CurrencyItem($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory);
29 12
            $data['homeCurrency'] = $homeCurrency->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['homeCurrency']);
30
        }
31
32
        // process foreign currency
33 16
        if (isset($data['foreignCurrency'])) {
34 1
            $foreignCurrency = new Type\CurrencyItem($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory);
35 1
            $data['foreignCurrency'] = $foreignCurrency->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['foreignCurrency']);
36
        }
37
38
        // process stock item
39 16
        if (isset($data['stockItem'])) {
40 7
            $stockItem = new Type\StockItem($this->namespacesPaths, $this->sanitizeEncoding, $this->companyRegistrationNumber, $this->resolveOptions, $this->normalizerFactory);
41 7
            $data['stockItem'] = $stockItem->setDirectionalVariable($this->useOneDirectionalVariables)->setData($data['stockItem']);
42
        }
43
44 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...
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 14
    public function getXML(): \SimpleXMLElement
51
    {
52 14
        if (is_null($this->namespace)) {
53 1
            throw new \LogicException('Namespace not set.');
54
        }
55
56 13
        if (is_null($this->nodePrefix)) {
57 1
            throw new \LogicException('Node name prefix not set.');
58
        }
59
60 12
        $xml = $this->createXML()->addChild($this->namespace . ':' . $this->nodePrefix . 'Item', '', $this->namespace($this->namespace));
61
62 12
        $this->addElements($xml, \array_merge($this->elements, ['parameters']), $this->namespace);
63
64 12
        return $xml;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 9
    protected function configureOptions(Common\OptionsResolver $resolver): void
71
    {
72
        // available options
73 9
        $resolver->setDefined($this->elements);
74
    }
75
}
76