Completed
Push — master ( b7e254...bcf326 )
by
unknown
09:07
created

PartialShipItems   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 23
c 1
b 0
f 0
dl 0
loc 64
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A findPartialShipItemWhereItem() 0 10 3
A setPartialShipItem() 0 11 2
A getArrayFromObject() 0 12 2
A findById() 0 10 3
A getPartialShipItems() 0 3 1
A __construct() 0 3 1
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);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $partialItem is correct as $this->findPartialShipIt...eItem($partialShipItem) targeting BitBag\SyliusMolliePlugi...tialShipItemWhereItem() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

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.

Loading history...
31
32
        if (null !== $partialItem) {
0 ignored issues
show
introduced by
The condition null !== $partialItem is always false.
Loading history...
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