1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file has been created by developers from BitBag. |
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
6
|
|
|
* another great project. |
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
8
|
|
|
* an email on [email protected]. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
declare(strict_types=1); |
12
|
|
|
|
13
|
|
|
namespace BitBag\SyliusMolliePlugin\DTO; |
14
|
|
|
|
15
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
16
|
|
|
use Doctrine\Common\Collections\Collection; |
17
|
|
|
|
18
|
|
|
final class PartialShipItems |
19
|
|
|
{ |
20
|
|
|
/** @var Collection */ |
21
|
|
|
private $partialShipItems; |
22
|
|
|
|
23
|
|
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
$this->partialShipItems = new ArrayCollection(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function setPartialShipItem(PartialShipItem $partialShipItem): void |
29
|
|
|
{ |
30
|
|
|
$partialItem = $this->findPartialShipItemWhereItem($partialShipItem); |
|
|
|
|
31
|
|
|
|
32
|
|
|
if (null !== $partialItem) { |
|
|
|
|
33
|
|
|
$partialItem->setQuantity($partialItem->getQuantity() + 1); |
34
|
|
|
|
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$this->partialShipItems->add($partialShipItem); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getPartialShipItems(): Collection |
42
|
|
|
{ |
43
|
|
|
return $this->partialShipItems; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function getArrayFromObject(): array |
47
|
|
|
{ |
48
|
|
|
$data = []; |
49
|
|
|
/** @var PartialShipItem $item */ |
50
|
|
|
foreach ($this->getPartialShipItems() as $item) { |
51
|
|
|
$data[] = [ |
52
|
|
|
'id' => $item->getLineId(), |
53
|
|
|
'quantity' => $item->getQuantity(), |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $data; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function findPartialShipItemWhereItem(PartialShipItem $partialShipItem): ?PartialShipItem |
61
|
|
|
{ |
62
|
|
|
/** @var PartialShipItem $item */ |
63
|
|
|
foreach ($this->getPartialShipItems() as $item) { |
64
|
|
|
if ($item->getId() === $partialShipItem->getId()) { |
65
|
|
|
return $item; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function findById(int $id): ?PartialShipItem |
73
|
|
|
{ |
74
|
|
|
/** @var PartialShipItem $item */ |
75
|
|
|
foreach ($this->getPartialShipItems() as $item) { |
76
|
|
|
if ($item->getId() === $id) { |
77
|
|
|
return $item; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return null; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.