Passed
Push — master ( 1fa5c8...3c4917 )
by Gabriel
02:55
created

Variant::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Waredesk\Models\Product;
4
5
use DateTime;
6
use JsonSerializable;
7
use Waredesk\Collections\Products\Variants\Items\Attributes as ItemsAttributes;
8
use Waredesk\Collections\Products\Variants\Attributes;
9
use Waredesk\Collections\Products\Variants\Codes;
10
use Waredesk\Collections\Products\Variants\Prices;
11
use Waredesk\Entity;
12
use Waredesk\Image;
13
use Waredesk\ReplaceableEntity;
14
15
class Variant implements Entity, ReplaceableEntity, JsonSerializable
16
{
17
    public const WEIGHT_UNIT_IMPERIAL = 'imperial';
18
    public const WEIGHT_UNIT_METRIC = 'metric';
19
    public const LENGTH_UNIT_IMPERIAL = 'imperial';
20
    public const LENGTH_UNIT_METRIC = 'metric';
21
22
    private $id;
23
    private $images;
24
    private $attributes;
25
    private $prices;
26
    private $codes;
27
    private $items_attributes;
28
    private $name;
29
    private $description;
30
    private $notes;
31
    private $weight_unit = self::WEIGHT_UNIT_METRIC;
32
    private $length_unit = self::LENGTH_UNIT_METRIC;
33
    private $weight;
34
    private $width;
35
    private $height;
36
    private $depth;
37
    private $creation;
38
    private $modification;
39
40
    /**
41
     * @var Image
42
     */
43
    private $pendingImage;
44
45
    /**
46
     * @var bool
47
     */
48
    private $deleteImage = false;
49
50 5
    public function __construct()
51
    {
52 5
        $this->attributes = new Attributes();
53 5
        $this->codes = new Codes();
54 5
        $this->prices = new Prices();
55 5
        $this->items_attributes = new ItemsAttributes();
56 5
    }
57
58
    public function __clone()
59
    {
60
        $this->attributes = clone $this->attributes;
61
        $this->codes = clone $this->codes;
62
        $this->prices = clone $this->prices;
63
    }
64
65 4
    public function getId(): ? string
66
    {
67 4
        return $this->id;
68
    }
69
70 1
    public function getImages(): ? array
71
    {
72 1
        return $this->images;
73
    }
74
75 3
    public function getAttributes(): ? Attributes
76
    {
77 3
        return $this->attributes;
78
    }
79
80 3
    public function getPrices(): ? Prices
81
    {
82 3
        return $this->prices;
83
    }
84
85 3
    public function getCodes(): ? Codes
86
    {
87 3
        return $this->codes;
88
    }
89
90 3
    public function getItemsAttributes(): ? ItemsAttributes
91
    {
92 3
        return $this->items_attributes;
93
    }
94
95 3
    public function getName(): ? string
96
    {
97 3
        return $this->name;
98
    }
99
100 3
    public function getDescription(): ? string
101
    {
102 3
        return $this->description;
103
    }
104
105 3
    public function getNotes(): ? string
106
    {
107 3
        return $this->notes;
108
    }
109
110 3
    public function getWeightUnit(): ? string
111
    {
112 3
        return $this->weight_unit;
113
    }
114
115 3
    public function getLengthUnit(): ? string
116
    {
117 3
        return $this->length_unit;
118
    }
119
120 3
    public function getWeight(): ? float
121
    {
122 3
        return $this->weight;
123
    }
124
125 3
    public function getWidth(): ? float
126
    {
127 3
        return $this->width;
128
    }
129
130 3
    public function getHeight(): ? float
131
    {
132 3
        return $this->height;
133
    }
134
135 3
    public function getDepth(): ? float
136
    {
137 3
        return $this->depth;
138
    }
139
140
    public function getCreation(): ? DateTime
141
    {
142
        return $this->creation;
143
    }
144
145
    public function getModification(): ? DateTime
146
    {
147
        return $this->modification;
148
    }
149
150 4
    public function reset(array $data = null)
151
    {
152 4
        if ($data) {
153 4
            foreach ($data as $key => $value) {
154
                switch ($key) {
155 4
                    case 'id':
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
156 4
                        $this->id = $value;
157 4
                        break;
158 4
                    case 'images':
159 4
                        $this->deleteImage = false;
160 4
                        $this->pendingImage = null;
161 4
                        $this->images = $value;
162 4
                        break;
163 4
                    case 'attributes':
164 4
                        $this->attributes = $value;
165 4
                        break;
166 4
                    case 'prices':
167 4
                        $this->prices = $value;
168 4
                        break;
169 4
                    case 'codes':
170 4
                        $this->codes = $value;
171 4
                        break;
172 4
                    case 'items_attributes':
173 4
                        $this->items_attributes = $value;
174 4
                        break;
175 4
                    case 'name':
176 4
                        $this->name = $value;
177 4
                        break;
178 4
                    case 'description':
179 4
                        $this->description = $value;
180 4
                        break;
181 4
                    case 'notes':
182 4
                        $this->notes = $value;
183 4
                        break;
184 4
                    case 'weight_unit':
185 4
                        $this->weight_unit = $value;
186 4
                        break;
187 4
                    case 'length_unit':
188 4
                        $this->length_unit = $value;
189 4
                        break;
190 4
                    case 'weight':
191 4
                        $this->weight = $value;
192 4
                        break;
193 4
                    case 'width':
194 4
                        $this->width = $value;
195 4
                        break;
196 4
                    case 'height':
197 4
                        $this->height = $value;
198 4
                        break;
199 4
                    case 'depth':
200 4
                        $this->depth = $value;
201 4
                        break;
202 4
                    case 'creation':
203 4
                        $this->creation = $value;
204 4
                        break;
205 4
                    case 'modification':
206 4
                        $this->modification = $value;
207 4
                        break;
208
                }
209
            }
210
        }
211 4
    }
212
213
    public function deleteImage()
214
    {
215
        $this->deleteImage = true;
216
    }
217
218 1
    public function setImage(Image $image = null)
219
    {
220 1
        $this->pendingImage = $image;
221 1
    }
222
223 3
    public function setName(string $name)
224
    {
225 3
        $this->name = $name;
226 3
    }
227
228
    public function setDescription(string $description = null)
229
    {
230
        $this->description = $description;
231
    }
232
233
    public function setNotes(string $notes = null)
234
    {
235
        $this->notes = $notes;
236
    }
237
238
    public function setWeightUnit(string $weight_unit = null)
239
    {
240
        $this->weight_unit = $weight_unit;
241
    }
242
243
    public function setLengthUnit(string $length_unit = null)
244
    {
245
        $this->length_unit = $length_unit;
246
    }
247
248
    public function setWeight(float $weight = null)
249
    {
250
        $this->weight = $weight;
251
    }
252
253
    public function setWidth(float $width = null)
254
    {
255
        $this->width = $width;
256
    }
257
258
    public function setHeight(float $height = null)
259
    {
260
        $this->height = $height;
261
    }
262
263
    public function setDepth(float $depth = null)
264
    {
265
        $this->depth = $depth;
266
    }
267
268 3
    public function jsonSerialize(): array
269
    {
270
        $returnValue = [
271 3
            'attributes' => $this->getAttributes()->jsonSerialize(),
272 3
            'prices' => $this->getPrices()->jsonSerialize(),
273 3
            'codes' => $this->getCodes()->jsonSerialize(),
274 3
            'items_attributes' => $this->getItemsAttributes()->jsonSerialize(),
275 3
            'name' => $this->getName(),
276 3
            'description' => $this->getDescription(),
277 3
            'notes' => $this->getNotes(),
278 3
            'weight_unit' => $this->getWeightUnit(),
279 3
            'length_unit' => $this->getLengthUnit(),
280 3
            'weight' => $this->getWeight(),
281 3
            'width' => $this->getWidth(),
282 3
            'height' => $this->getHeight(),
283 3
            'depth' => $this->getDepth(),
284
        ];
285 3
        if ($this->pendingImage) {
286 1
            $returnValue['image'] = $this->pendingImage->toBase64();
287 2
        } elseif ($this->deleteImage) {
288
            $returnValue['image'] = null;
289
        }
290 3
        if ($this->getId()) {
291
            $returnValue = array_merge(['id' => $this->getId()], $returnValue);
292
        }
293 3
        return $returnValue;
294
    }
295
}
296