Passed
Push — master ( c2fcdd...0160cf )
by Aleksandr
02:39 queued 01:02
created

OfferPackage   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 60.71%

Importance

Changes 0
Metric Value
wmc 18
eloc 25
dl 0
loc 82
ccs 17
cts 28
cp 0.6071
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A propertyAliases() 0 4 1
A getOffersById() 0 9 3
A getOffers() 0 8 5
A loadXml() 0 7 2
A getOfferById() 0 8 3
A getPriceTypes() 0 8 4
1
<?php
2
3
4
namespace Zenwalker\CommerceML\Model;
5
6
7
/**
8
 * Class OfferPackage
9
 *
10
 * @package Zenwalker\CommerceML\Model
11
 * @property Offer[] offers
12
 * @property string containsOnlyChanges
13
 */
14
class OfferPackage extends Simple
15
{
16
    /**
17
     * @var Offer[]
18
     */
19
    protected $offers = [];
20
21
    /**
22
     * @var Simple[] array
23
     */
24
    protected $priceTypes = [];
25
26 1
    public function propertyAliases()
27
    {
28 1
        return array_merge(parent::propertyAliases(), [
29 1
            'СодержитТолькоИзменения' => 'containsOnlyChanges'
30
        ]);
31
    }
32
33 14
    public function loadXml()
34
    {
35 14
        if ($this->owner->offersXml) {
36 14
            return $this->owner->offersXml->ПакетПредложений;
37
        }
38
39
        return null;
40
    }
41
42
    /**
43
     * @return Offer[]
44
     */
45 4
    public function getOffers()
46
    {
47 4
        if (empty($this->offers) && $this->xml && $this->xml->Предложения) {
48 4
            foreach ($this->xml->Предложения->Предложение as $offer) {
49 4
                $this->offers[] = new Offer($this->owner, $offer);
50
            }
51
        }
52 4
        return $this->offers;
53
    }
54
55
    /**
56
     * @return Simple[]
57
     */
58
    public function getPriceTypes()
59
    {
60
        if (empty($this->priceTypes) && $this->xml) {
61
            foreach ($this->xpath('//c:ТипыЦен/c:ТипЦены') as $type) {
62
                $this->priceTypes[] = new Simple($this->owner, $type);
63
            }
64
        }
65
        return $this->priceTypes;
66
    }
67
68
    /**
69
     * @param $id
70
     * @return null|Offer
71
     * @deprecated will removed in 0.3.0
72
     */
73
    public function getOfferById($id)
74
    {
75
        foreach ($this->getOffers() as $offer) {
76
            if ($offer->getClearId() === $id) {
77
                return $offer;
78
            }
79
        }
80
        return null;
81
    }
82
83
    /**
84
     * @param $id
85
     * @return Offer[]
86
     */
87 4
    public function getOffersById($id)
88
    {
89 4
        $result = [];
90 4
        foreach ($this->getOffers() as $offer) {
91 4
            if ($offer->getClearId() === $id) {
92 4
                $result[] = $offer;
93
            }
94
        }
95 4
        return $result;
96
    }
97
}