Passed
Push — master ( 3ff747...952456 )
by Aleksandr
01:46
created

Product::getGroup()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 0
crap 3.0261
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 \SimpleXMLElement Штрихкод
13
 * @property \SimpleXMLElement Артикул
14
 * @property \SimpleXMLElement Наименование
15
 * @property \SimpleXMLElement БазоваяЕдиница
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<Property>
53
     */
54 2
    public function getProperties()
55
    {
56 2
        if (!$this->properties) {
57 2
            $this->properties = new PropertyCollection($this->owner, $this->xml->ЗначенияСвойств);
58
        }
59 2
        return $this->properties;
60
    }
61
62
    /**
63
     * @return SpecificationCollection|null|array
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...
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...
Bug Best Practice introduced by
The expression return $this->getOffer()...->getPrices() : array() also could return the type Zenwalker\CommerceML\Model\Price which is incompatible with the documented return type Zenwalker\CommerceML\Model\Price[].
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 1
    public function getGroup()
95
    {
96 1
        if (!$this->group) {
97 1
            if (!$this->Группы) {
98
                return null;
99
            }
100 1
            $groupId = (string)$this->Группы->Ид;
101 1
            $this->group = $this->owner->classifier->getGroupById($groupId);
102
        }
103 1
        return $this->group;
104
    }
105
106
    /**
107
     * @return null|Offer
108
     * @deprecated will removed in 0.3.0
109
     */
110
    public function getOffer()
111
    {
112
        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

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