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
![]() |
|||
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 |