| Total Complexity | 10 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | class PropertyCollection extends Simple |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @param $id |
||
| 19 | * @return Property|null |
||
| 20 | */ |
||
| 21 | 2 | public function getById($id) |
|
| 22 | { |
||
| 23 | 2 | foreach ($this as $property) { |
|
| 24 | 2 | if ($property->id === (string)$id) { |
|
| 25 | 2 | return $property; |
|
| 26 | } |
||
| 27 | } |
||
| 28 | 1 | return null; |
|
| 29 | } |
||
| 30 | |||
| 31 | 2 | protected function loadPropertiesValue() |
|
| 32 | { |
||
| 33 | 2 | foreach ($this->xml->ЗначенияСвойства as $property) { |
|
|
|
|||
| 34 | 2 | $properties = $this->owner->classifier->getProperties(); |
|
| 35 | 2 | $object = clone $properties->getById((string)$property->Ид); |
|
| 36 | 2 | $object->productId = (string)$this->xpath('..')[0]->Ид; |
|
| 37 | 2 | $object->init(); |
|
| 38 | 2 | $this->append($object); |
|
| 39 | } |
||
| 40 | 2 | } |
|
| 41 | |||
| 42 | 2 | protected function loadProperties() |
|
| 43 | { |
||
| 44 | 2 | foreach ($this->xml->Свойство as $property) { |
|
| 45 | 2 | $this->append(new Property($this->owner, $property)); |
|
| 46 | } |
||
| 47 | 2 | } |
|
| 48 | |||
| 49 | 2 | public function init() |
|
| 50 | { |
||
| 51 | 2 | if (isset($this->xml->ЗначенияСвойства)) { |
|
| 52 | 2 | $this->loadPropertiesValue(); |
|
| 53 | } |
||
| 54 | 2 | if (isset($this->xml->Свойство)) { |
|
| 55 | 2 | $this->loadProperties(); |
|
| 56 | } |
||
| 57 | 2 | parent::init(); |
|
| 58 | } |
||
| 59 | } |