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