| Total Complexity | 10 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Coverage | 92.86% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | class Catalog extends Simple |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var Product[] |
||
| 18 | */ |
||
| 19 | protected $products = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $id |
||
| 23 | * @return null|Product |
||
| 24 | */ |
||
| 25 | 3 | public function getById($id) |
|
| 26 | { |
||
| 27 | 3 | foreach ($this->getProducts() as $product) { |
|
| 28 | 3 | if ($product->id === $id) { |
|
| 29 | 3 | return $product; |
|
| 30 | } |
||
| 31 | } |
||
| 32 | 1 | return null; |
|
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @return Product[] |
||
| 37 | */ |
||
| 38 | 12 | public function getProducts() |
|
| 39 | { |
||
| 40 | 12 | if (empty($this->products) && $this->xml && $this->xml->Товары) { |
|
|
|
|||
| 41 | 12 | foreach ($this->xml->Товары->Товар as $product) { |
|
| 42 | 12 | $this->products[] = new Product($this->owner, $product); |
|
| 43 | } |
||
| 44 | } |
||
| 45 | 12 | return $this->products; |
|
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @return \SimpleXMLElement |
||
| 50 | */ |
||
| 51 | 31 | public function loadXml() |
|
| 52 | { |
||
| 53 | 31 | if ($this->owner->importXml) { |
|
| 54 | 31 | return $this->owner->importXml->Каталог; |
|
| 55 | } |
||
| 56 | |||
| 57 | return null; |
||
| 58 | } |
||
| 59 | } |