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