Completed
Push — master ( cacd0e...e6ba08 )
by Gabriel
02:29
created

Variant::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Waredesk\Models\Product;
4
5
use DateTime;
6
use JsonSerializable;
7
use Waredesk\Collections\Products\Variants\Codes;
8
use Waredesk\Collections\Products\Variants\Options;
9
use Waredesk\Collections\Products\Variants\Prices;
10
use Waredesk\Image;
11
12
class Variant implements JsonSerializable
13
{
14
    private $id;
15
    private $images;
16
    private $options;
17
    private $codes;
18
    private $prices;
19
    private $name;
20
    private $description;
21
    private $notes;
22
    private $weight_unit;
23
    private $length_unit;
24
    private $weight;
25
    private $width;
26
    private $height;
27
    private $depth;
28
    private $creation_datetime;
29
    private $modification_datetime;
30
31
    /**
32
     * @var Image
33
     */
34
    private $pendingImage;
35
36
    /**
37
     * @var Image
38
     */
39
    private $deleteImage;
40
41 3
    public function __construct()
42
    {
43 3
        $this->options = new Options();
44 3
        $this->codes = new Codes();
45 3
        $this->prices = new Prices();
46 3
    }
47
48
    public function getId(): ?int
49
    {
50
        return $this->id;
51
    }
52
53 1
    public function getImages(): ?array
54
    {
55 1
        return $this->images;
56
    }
57
58 2
    public function getOptions(): ?Options
59
    {
60 2
        return $this->options;
61
    }
62
63 2
    public function getCodes(): ?Codes
64
    {
65 2
        return $this->codes;
66
    }
67
68 2
    public function getPrices(): ?Prices
69
    {
70 2
        return $this->prices;
71
    }
72
73 2
    public function getName(): ?string
74
    {
75 2
        return $this->name;
76
    }
77
78 2
    public function getDescription(): ?string
79
    {
80 2
        return $this->description;
81
    }
82
83 2
    public function getNotes(): ?string
84
    {
85 2
        return $this->notes;
86
    }
87
88 2
    public function getWeightUnit(): ?string
89
    {
90 2
        return $this->weight_unit;
91
    }
92
93 2
    public function getLengthUnit(): ?string
94
    {
95 2
        return $this->length_unit;
96
    }
97
98 2
    public function getWeight(): ?float
99
    {
100 2
        return $this->weight;
101
    }
102
103 2
    public function getWidth(): ?float
104
    {
105 2
        return $this->width;
106
    }
107
108 2
    public function getHeight(): ?float
109
    {
110 2
        return $this->height;
111
    }
112
113 2
    public function getDepth(): ?float
114
    {
115 2
        return $this->depth;
116
    }
117
118
    public function getCreationDatetime(): ?DateTime
119
    {
120
        return $this->creation_datetime;
121
    }
122
123
    public function getModificationDatetime(): ?DateTime
124
    {
125
        return $this->modification_datetime;
126
    }
127
128 3
    public function reset(array $data = null)
129
    {
130 3
        if ($data) {
131 3
            foreach ($data as $key => $value) {
132
                switch ($key) {
133 3
                    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...
134 3
                        $this->id = $value;
135 3
                        break;
136 3
                    case 'images':
137 3
                        $this->deleteImage = false;
0 ignored issues
show
Documentation Bug introduced by
It seems like false of type false is incompatible with the declared type object<Waredesk\Image> of property $deleteImage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
138 3
                        $this->pendingImage = null;
139 3
                        $this->images = $value;
140 3
                        break;
141 3
                    case 'options':
142 3
                        $this->options = $value;
143 3
                        break;
144 3
                    case 'codes':
145 3
                        $this->codes = $value;
146 3
                        break;
147 3
                    case 'prices':
148 3
                        $this->prices = $value;
149 3
                        break;
150 3
                    case 'name':
151 3
                        $this->name = $value;
152 3
                        break;
153 3
                    case 'description':
154 3
                        $this->description = $value;
155 3
                        break;
156 3
                    case 'notes':
157 3
                        $this->notes = $value;
158 3
                        break;
159 3
                    case 'weight_unit':
160 3
                        $this->weight_unit = $value;
161 3
                        break;
162 3
                    case 'length_unit':
163 3
                        $this->length_unit = $value;
164 3
                        break;
165 3
                    case 'weight':
166 3
                        $this->weight = $value;
167 3
                        break;
168 3
                    case 'width':
169 3
                        $this->width = $value;
170 3
                        break;
171 3
                    case 'height':
172 3
                        $this->height = $value;
173 3
                        break;
174 3
                    case 'depth':
175 3
                        $this->depth = $value;
176 3
                        break;
177 3
                    case 'creation_datetime':
178 3
                        $this->creation_datetime = $value;
179 3
                        break;
180 3
                    case 'modification_datetime':
181 3
                        $this->modification_datetime = $value;
182 3
                        break;
183
                }
184
            }
185
        }
186 3
    }
187
188
    public function deleteImage()
189
    {
190
        $this->deleteImage = true;
0 ignored issues
show
Documentation Bug introduced by
It seems like true of type boolean is incompatible with the declared type object<Waredesk\Image> of property $deleteImage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
191
    }
192
193 1
    public function setImage(Image $image = null)
194
    {
195 1
        $this->pendingImage = $image;
196 1
    }
197
198
    public function setName(string $name)
199
    {
200
        $this->name = $name;
201
    }
202
203 2
    public function setDescription(string $description = null)
204
    {
205 2
        $this->description = $description;
206 2
    }
207
208
    public function setNotes(string $notes = null)
209
    {
210
        $this->notes = $notes;
211
    }
212
213
    public function setWeightUnit(string $weight_unit = null)
214
    {
215
        $this->weight_unit = $weight_unit;
216
    }
217
218
    public function setLengthUnit(string $length_unit = null)
219
    {
220
        $this->length_unit = $length_unit;
221
    }
222
223
    public function setWeight(float $weight = null)
224
    {
225
        $this->weight = $weight;
226
    }
227
228
    public function setWidth(float $width = null)
229
    {
230
        $this->width = $width;
231
    }
232
233
    public function setHeight(float $height = null)
234
    {
235
        $this->height = $height;
236
    }
237
238
    public function setDepth(float $depth = null)
239
    {
240
        $this->depth = $depth;
241
    }
242
243 2
    public function jsonSerialize()
244
    {
245
        $returnValue = [
246 2
            'name' => $this->getName(),
247 2
            'description' => $this->getDescription(),
248 2
            'notes' => $this->getNotes(),
249 2
            'options' => $this->getOptions()->jsonSerialize(),
250 2
            'codes' => $this->getCodes()->jsonSerialize(),
251 2
            'prices' => $this->getPrices()->jsonSerialize(),
252 2
            'weight_unit' => $this->getWeightUnit(),
253 2
            'length_unit' => $this->getLengthUnit(),
254 2
            'weight' => $this->getWeight(),
255 2
            'width' => $this->getWidth(),
256 2
            'height' => $this->getHeight(),
257 2
            'depth' => $this->getDepth(),
258
        ];
259 2
        if ($this->pendingImage) {
260 1
            $returnValue['image'] = $this->pendingImage->toBase64();
261 1
        } else if ($this->deleteImage) {
262
            $returnValue['image'] = null;
263
        }
264 2
        return $returnValue;
265
    }
266
}
267