Issues (31)

src/Pohoda/Supplier.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;
13
14
/**
15
 * @property array{
16
 *     stockItem?: Supplier\StockItem,
17
 *     suppliers?: Supplier\SupplierItem,
18
 * } $data
19
 */
20
class Supplier extends AbstractAgenda
21
{
22 1
    public function getImportRoot(): string
23
    {
24 1
        return 'lst:supplier';
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 2
    public function setData(array $data): parent
31
    {
32
        // process stockItem
33 2
        if (isset($data['stockItem'])) {
34 2
            $stockItem = new Supplier\StockItem($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory);
35 2
            $stockItem->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($data['stockItem']);
36 2
            $data['stockItem'] = $stockItem;
37
        }
38
39
        // process suppliers
40 2
        if (isset($data['suppliers']) && is_array($data['suppliers'])) {
41 2
            $data['suppliers'] = \array_map(function ($supplier) {
42 2
                $supplierItem = new Supplier\SupplierItem($this->namespacesPaths, $this->sanitizeEncoding, $this->normalizerFactory);
43 2
                $supplierItem->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($supplier['supplierItem']);
44 2
                return $supplierItem;
45 2
            }, $data['suppliers']);
46
        }
47
48 2
        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...
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function getXML(): \SimpleXMLElement
55
    {
56 1
        $xml = $this->createXML()->addChild('sup:supplier', '', $this->namespace('sup'));
57 1
        $xml->addAttribute('version', '2.0');
58
59 1
        $this->addElements($xml, ['stockItem', 'suppliers'], 'sup');
60
61 1
        return $xml;
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 1
    protected function configureOptions(Common\OptionsResolver $resolver): void
68
    {
69
        // available options
70 1
        $resolver->setDefined(['stockItem', 'suppliers']);
71
    }
72
}
73