Completed
Push — master ( d81c19...f57266 )
by Kamil
20s
created

src/Sylius/Component/Core/Model/ProductVariant.php (1 issue)

assigning incompatible types to properties.

Bug Documentation Major

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Component\Core\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Sylius\Component\Product\Model\ProductVariant as BaseVariant;
19
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
20
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
21
22
class ProductVariant extends BaseVariant implements ProductVariantInterface
23
{
24
    /**
25
     * @var int
26
     */
27
    protected $version = 1;
28
29
    /**
30
     * @var int
31
     */
32
    protected $onHold = 0;
33
34
    /**
35
     * @var int
36
     */
37
    protected $onHand = 0;
38
39
    /**
40
     * @var bool
41
     */
42
    protected $tracked = false;
43
44
    /**
45
     * @var float
46
     */
47
    protected $weight;
48
49
    /**
50
     * @var float
51
     */
52
    protected $width;
53
54
    /**
55
     * @var float
56
     */
57
    protected $height;
58
59
    /**
60
     * @var float
61
     */
62
    protected $depth;
63
64
    /**
65
     * @var TaxCategoryInterface
66
     */
67
    protected $taxCategory;
68
69
    /**
70
     * @var ShippingCategoryInterface
71
     */
72
    protected $shippingCategory;
73
74
    /**
75
     * @var Collection
76
     */
77
    protected $channelPricings;
78
79
    /**
80
     * @var bool
81
     */
82
    protected $shippingRequired = true;
83
84
    /**
85
     * @var Collection|ProductImageInterface[]
86
     */
87
    protected $images;
88
89
    public function __construct()
90
    {
91
        parent::__construct();
92
93
        $this->channelPricings = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\Collections\Collection> of property $channelPricings.

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...
94
        $this->images = new ArrayCollection();
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function __toString(): string
101
    {
102
        $string = (string) $this->getProduct()->getName();
103
104
        if (!$this->getOptionValues()->isEmpty()) {
105
            $string .= '(';
106
107
            foreach ($this->getOptionValues() as $option) {
108
                $string .= $option->getOption()->getName() . ': ' . $option->getValue() . ', ';
109
            }
110
111
            $string = substr($string, 0, -2) . ')';
112
        }
113
114
        return $string;
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function getVersion(): ?int
121
    {
122
        return $this->version;
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function setVersion(?int $version): void
129
    {
130
        $this->version = $version;
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function isInStock(): bool
137
    {
138
        return 0 < $this->onHand;
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144
    public function getOnHold(): ?int
145
    {
146
        return $this->onHold;
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function setOnHold(?int $onHold): void
153
    {
154
        $this->onHold = $onHold;
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function getOnHand(): ?int
161
    {
162
        return $this->onHand;
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     */
168
    public function setOnHand(?int $onHand): void
169
    {
170
        $this->onHand = (0 > $onHand) ? 0 : $onHand;
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     */
176
    public function isTracked(): bool
177
    {
178
        return $this->tracked;
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184
    public function setTracked(bool $tracked): void
185
    {
186
        $this->tracked = $tracked;
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192
    public function getInventoryName(): ?string
193
    {
194
        return $this->getProduct()->getName();
195
    }
196
197
    /**
198
     * {@inheritdoc}
199
     */
200
    public function getShippingCategory(): ?ShippingCategoryInterface
201
    {
202
        return $this->shippingCategory;
203
    }
204
205
    /**
206
     * {@inheritdoc}
207
     */
208
    public function setShippingCategory(?ShippingCategoryInterface $category): void
209
    {
210
        $this->shippingCategory = $category;
211
    }
212
213
    /**
214
     * {@inheritdoc}
215
     */
216
    public function getWeight(): ?float
217
    {
218
        return $this->weight;
219
    }
220
221
    /**
222
     * {@inheritdoc}
223
     */
224
    public function setWeight(?float $weight): void
225
    {
226
        $this->weight = $weight;
227
    }
228
229
    /**
230
     * {@inheritdoc}
231
     */
232
    public function getWidth(): ?float
233
    {
234
        return $this->width;
235
    }
236
237
    /**
238
     * {@inheritdoc}
239
     */
240
    public function setWidth(?float $width): void
241
    {
242
        $this->width = $width;
243
    }
244
245
    /**
246
     * {@inheritdoc}
247
     */
248
    public function getHeight(): ?float
249
    {
250
        return $this->height;
251
    }
252
253
    /**
254
     * {@inheritdoc}
255
     */
256
    public function setHeight(?float $height): void
257
    {
258
        $this->height = $height;
259
    }
260
261
    /**
262
     * {@inheritdoc}
263
     */
264
    public function getDepth(): ?float
265
    {
266
        return $this->depth;
267
    }
268
269
    /**
270
     * {@inheritdoc}
271
     */
272
    public function setDepth(?float $depth): void
273
    {
274
        $this->depth = $depth;
275
    }
276
277
    /**
278
     * {@inheritdoc}
279
     */
280
    public function getShippingWeight(): ?float
281
    {
282
        return $this->getWeight();
283
    }
284
285
    /**
286
     * {@inheritdoc}
287
     */
288
    public function getShippingWidth(): ?float
289
    {
290
        return $this->getWidth();
291
    }
292
293
    /**
294
     * {@inheritdoc}
295
     */
296
    public function getShippingHeight(): ?float
297
    {
298
        return $this->getHeight();
299
    }
300
301
    /**
302
     * {@inheritdoc}
303
     */
304
    public function getShippingDepth(): ?float
305
    {
306
        return $this->getDepth();
307
    }
308
309
    /**
310
     * {@inheritdoc}
311
     */
312
    public function getShippingVolume(): ?float
313
    {
314
        return $this->depth * $this->height * $this->width;
315
    }
316
317
    /**
318
     * {@inheritdoc}
319
     */
320
    public function getTaxCategory(): ?TaxCategoryInterface
321
    {
322
        return $this->taxCategory;
323
    }
324
325
    /**
326
     * {@inheritdoc}
327
     */
328
    public function setTaxCategory(?TaxCategoryInterface $category): void
329
    {
330
        $this->taxCategory = $category;
331
    }
332
333
    /**
334
     * {@inheritdoc}
335
     */
336
    public function getChannelPricings(): Collection
337
    {
338
        return $this->channelPricings;
339
    }
340
341
    /**
342
     * {@inheritdoc}
343
     */
344
    public function getChannelPricingForChannel(ChannelInterface $channel): ?ChannelPricingInterface
345
    {
346
        if ($this->channelPricings->containsKey($channel->getCode())) {
347
            return $this->channelPricings->get($channel->getCode());
348
        }
349
350
        return null;
351
    }
352
353
    /**
354
     * {@inheritdoc}
355
     */
356
    public function hasChannelPricingForChannel(ChannelInterface $channel): bool
357
    {
358
        return null !== $this->getChannelPricingForChannel($channel);
359
    }
360
361
    /**
362
     * {@inheritdoc}
363
     */
364
    public function hasChannelPricing(ChannelPricingInterface $channelPricing): bool
365
    {
366
        return $this->channelPricings->contains($channelPricing);
367
    }
368
369
    /**
370
     * {@inheritdoc}
371
     */
372
    public function addChannelPricing(ChannelPricingInterface $channelPricing): void
373
    {
374
        if (!$this->hasChannelPricing($channelPricing)) {
375
            $channelPricing->setProductVariant($this);
376
            $this->channelPricings->set($channelPricing->getChannelCode(), $channelPricing);
377
        }
378
    }
379
380
    /**
381
     * {@inheritdoc}
382
     */
383
    public function removeChannelPricing(ChannelPricingInterface $channelPricing): void
384
    {
385
        if ($this->hasChannelPricing($channelPricing)) {
386
            $channelPricing->setProductVariant(null);
387
            $this->channelPricings->remove($channelPricing->getChannelCode());
388
        }
389
    }
390
391
    /**
392
     * {@inheritdoc}
393
     */
394
    public function isShippingRequired(): bool
395
    {
396
        return $this->shippingRequired;
397
    }
398
399
    /**
400
     * {@inheritdoc}
401
     */
402
    public function setShippingRequired(bool $shippingRequired): void
403
    {
404
        $this->shippingRequired = $shippingRequired;
405
    }
406
407
    /**
408
     * {@inheritdoc}
409
     */
410
    public function getImages(): Collection
411
    {
412
        return $this->images;
413
    }
414
415
    /**
416
     * {@inheritdoc}
417
     */
418
    public function getImagesByType(string $type): Collection
419
    {
420
        return $this->images->filter(function (ProductImageInterface $image) use ($type): bool {
421
            return $type === $image->getType();
422
        });
423
    }
424
425
    /**
426
     * {@inheritdoc}
427
     */
428
    public function hasImages(): bool
429
    {
430
        return !$this->images->isEmpty();
431
    }
432
433
    /**
434
     * {@inheritdoc}
435
     */
436
    public function hasImage(ProductImageInterface $image): bool
437
    {
438
        return $this->images->contains($image);
439
    }
440
441
    /**
442
     * {@inheritdoc}
443
     */
444
    public function addImage(ProductImageInterface $image): void
445
    {
446
        if ($this->hasImage($image)) {
447
            return;
448
        }
449
        $image->setOwner($this->getProduct());
450
        $image->addProductVariant($this);
451
        $this->images->add($image);
452
    }
453
454
    /**
455
     * {@inheritdoc}
456
     */
457
    public function removeImage(ProductImageInterface $image): void
458
    {
459
        if ($this->hasImage($image)) {
460
            $this->images->removeElement($image);
461
        }
462
    }
463
}
464