Passed
Push — master ( 1cde7b...7c9c8d )
by Aleksandr
08:27
created

Catalog   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 13
c 1
b 0
f 0
dl 0
loc 44
ccs 13
cts 14
cp 0.9286
rs 10
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 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->Товары) {
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' on line 40 at column 64
Loading history...
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
}