Passed
Push — master ( 01a1a8...191f59 )
by Aleksandr
01:35
created

Catalog   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 10
eloc 14
dl 0
loc 43
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadXml() 0 6 2
A getById() 0 8 3
A getProducts() 0 8 5
1
<?php
2
3
4
namespace Zenwalker\CommerceML\Model;
5
6
/**
7
 * import.xml -> Каталог
8
 *
9
 * Class Catalog
10
 *
11
 * @package Zenwalker\CommerceML\Model
12
 * @property Product[] $products
13
 */
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()
52
    {
53 9
        if ($this->owner->importXml) {
54 9
            return $this->owner->importXml->Каталог;
55
        } else {
56
            return null;
57
        }
58
    }
59
}