alex-kalanis /
pohoda
| 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->normalizerFactory); |
|
| 34 | 1 | $price->setDirectionalVariable($this->useOneDirectionalVariables)->setResolveOptions($this->resolveOptions)->setData($stockPriceItem['stockPrice']); |
|
| 35 | 1 | return $price; |
|
| 36 | 1 | }, $data['stockPriceItem']); |
|
| 37 | } |
||
| 38 | |||
| 39 | 1 | return parent::setData($data); |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * {@inheritdoc} |
||
| 44 | */ |
||
| 45 | 1 | public function getXML(): \SimpleXMLElement |
|
| 46 | { |
||
| 47 | 1 | $xml = $this->createXML()->addChild('stk:stockItem', '', $this->namespace('stk')); |
|
| 48 | |||
| 49 | 1 | $this->addElements($xml, $this->elements, 'stk'); |
|
| 50 | |||
| 51 | 1 | return $xml; |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | 1 | protected function configureOptions(Common\OptionsResolver $resolver): void |
|
| 58 | { |
||
| 59 | // available options |
||
| 60 | 1 | $resolver->setDefined($this->elements); |
|
| 61 | |||
| 62 | 1 | $resolver->setNormalizer('id', $this->normalizerFactory->getClosure('int')); |
|
| 63 | 1 | $resolver->setNormalizer('count', $this->normalizerFactory->getClosure('float')); |
|
| 64 | 1 | $resolver->setNormalizer('quantity', $this->normalizerFactory->getClosure('float')); |
|
| 65 | } |
||
| 66 | } |
||
| 67 |