Passed
Push — master ( 191f59...1ee7f2 )
by Aleksandr
01:40
created

Product   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 35.7%

Importance

Changes 0
Metric Value
wmc 17
eloc 27
dl 0
loc 109
ccs 10
cts 28
cp 0.357
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getImages() 0 6 2
A getProperties() 0 6 2
A getPrices() 0 3 2
A getGroup() 0 12 5
A getSpecifications() 0 3 2
A getRequisites() 0 6 2
A getOffers() 0 3 1
A getOffer() 0 3 1
1
<?php namespace Zenwalker\CommerceML\Model;
2
3
use Zenwalker\CommerceML\Collections\ImageCollection;
4
use Zenwalker\CommerceML\Collections\PropertyCollection;
5
use Zenwalker\CommerceML\Collections\RequisiteCollection;
6
use Zenwalker\CommerceML\Collections\SpecificationCollection;
7
8
/**
9
 * Class Product
10
 *
11
 * @package Zenwalker\CommerceML\Model
12
 * @property string !Штрихкод
13
 * @property string !Артикул
14
 * @property string !Наименование
15
 *
16
 * @property \SimpleXMLElement !БазоваяЕдиница
17
 * @property ImageCollection images
18
 * @property Offer offer
19
 * @property Offer[] offers
20
 * @property Group group
21
 * @property RequisiteCollection requisites
22
 * @property Price[] prices
23
 * @property PropertyCollection properties
24
 */
25
class Product extends Simple
26
{
27
    /**
28
     * @var PropertyCollection Свойства продукта
29
     */
30
    protected $properties;
31
    /**
32
     * @var RequisiteCollection
33
     */
34
    protected $requisites;
35
    /**
36
     * @var SpecificationCollection
37
     */
38
    protected $specifications;
39
40
    /**
41
     * @var Price
42
     */
43
    protected $prices;
44
    /**
45
     * @var Group
46
     */
47
    protected $group;
48
49
    protected $images;
50
51
    /**
52
     * @return PropertyCollection<Simple>
53
     */
54
    public function getProperties()
55
    {
56
        if (!$this->properties) {
57
            $this->properties = new PropertyCollection($this->owner, $this->xml->ЗначенияСвойств);
58
        }
59
        return $this->properties;
60
    }
61
62
    /**
63
     * @return SpecificationCollection
64
     * @deprecated will removed in 0.3.0
65
     */
66
    public function getSpecifications()
67
    {
68
        return $this->getOffer() ? $this->getOffer()->getSpecifications() : null;
0 ignored issues
show
Deprecated Code introduced by
The function Zenwalker\CommerceML\Model\Product::getOffer() has been deprecated: will removed in 0.3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

68
        return $this->getOffer() ? /** @scrutinizer ignore-deprecated */ $this->getOffer()->getSpecifications() : null;

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug Best Practice introduced by
The expression return $this->getOffer()...Specifications() : null also could return the type array which is incompatible with the documented return type Zenwalker\CommerceML\Col...SpecificationCollection.
Loading history...
69
    }
70
71
    /**
72
     * @return Price[]
73
     * @deprecated will removed in 0.3.0
74
     */
75
    public function getPrices()
76
    {
77
        return $this->getOffer() ? $this->getOffer()->getPrices() : [];
0 ignored issues
show
Deprecated Code introduced by
The function Zenwalker\CommerceML\Model\Product::getOffer() has been deprecated: will removed in 0.3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

77
        return /** @scrutinizer ignore-deprecated */ $this->getOffer() ? $this->getOffer()->getPrices() : [];

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
78
    }
79
80
    /**
81
     * @return RequisiteCollection
82
     */
83 1
    public function getRequisites()
84
    {
85 1
        if (!$this->requisites) {
86 1
            $this->requisites = new RequisiteCollection($this->owner, $this->xml->ЗначенияРеквизитов);
87
        }
88 1
        return $this->requisites;
89
    }
90
91
    /**
92
     * @return Group
93
     */
94
    public function getGroup()
95
    {
96
        if (!$this->group) {
97
            foreach ($this->owner->classifier->getGroups() as $group) {
98
                if ($group->id === $this->Группы->Ид) {
0 ignored issues
show
Bug Best Practice introduced by
The property Группы does not exist on Zenwalker\CommerceML\Model\Product. Since you implemented __get, consider adding a @property annotation.
Loading history...
99
                    $this->group = $group;
100
                } elseif ($child = $group->getChildById($this->Группы->Ид)) {
101
                    $this->group = $child;
102
                }
103
            }
104
        }
105
        return $this->group;
106
    }
107
108
    /**
109
     * @return null|Offer
110
     * @deprecated will removed in 0.3.0
111
     */
112
    public function getOffer()
113
    {
114
        return $this->owner->offerPackage->getOfferById($this->getClearId());
0 ignored issues
show
Deprecated Code introduced by
The function Zenwalker\CommerceML\Mod...Package::getOfferById() has been deprecated: will removed in 0.3.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

114
        return /** @scrutinizer ignore-deprecated */ $this->owner->offerPackage->getOfferById($this->getClearId());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
115
    }
116
117
    /**
118
     * @return Offer[]
119
     */
120 1
    public function getOffers()
121
    {
122 1
        return $this->owner->offerPackage->getOffersById($this->getClearId());
123
    }
124
125
    /**
126
     * @return ImageCollection
127
     */
128 1
    public function getImages()
129
    {
130 1
        if (!$this->images) {
131 1
            $this->images = new ImageCollection($this->owner, $this->xml->Картинка);
132
        }
133 1
        return $this->images;
134
    }
135
}
136