Completed
Push — master ( a88c94...f713d7 )
by Matthias
13s
created

ProductBundleSlot::removeProduct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Created by solutionDrive GmbH
7
 *
8
 * @copyright 2018 solutionDrive GmbH
9
 */
10
11
namespace solutionDrive\SyliusProductBundlesPlugin\Entity;
12
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Sylius\Component\Core\Model\ProductInterface;
16
use Sylius\Component\Resource\Model\ResourceInterface;
17
18
class ProductBundleSlot implements ProductBundleSlotInterface, ResourceInterface
19
{
20
    /** @var int */
21
    private $id;
22
23
    /** @var string|null */
24
    private $name;
25
26
    /** @var int */
27
    private $position = 0;
28
29
    /** @var ProductBundleInterface */
30
    private $bundle;
31
32
    /** @var ProductInterface[]|Collection|ArrayCollection */
33
    private $products;
34
35
    public function __construct()
36
    {
37
        $this->products = new ArrayCollection();
38
    }
39
40
    public function getId(): int
41
    {
42
        return $this->id;
43
    }
44
45
    public function getName(): ?string
46
    {
47
        return $this->name;
48
    }
49
50
    public function setName(string $name): void
51
    {
52
        $this->name = $name;
53
    }
54
55
    public function getPosition(): int
56
    {
57
        return $this->position;
58
    }
59
60
    public function setPosition(?int $position): void
61
    {
62
        $this->position = (int) $position;
63
    }
64
65
    public function getBundle(): ?ProductBundleInterface
66
    {
67
        return $this->bundle;
68
    }
69
70
    public function setBundle(?ProductBundleInterface $bundle): void
71
    {
72
        $this->bundle = $bundle;
73
    }
74
75
    public function getProducts(): Collection
76
    {
77
        return $this->products;
78
    }
79
80
    public function addProduct(ProductInterface $product): void
81
    {
82
        if (false === $this->hasProduct($product)) {
83
            $this->products->add($product);
84
        }
85
    }
86
87
    public function removeProduct(ProductInterface $product): void
88
    {
89
        if ($this->hasProduct($product)) {
90
            $this->products->removeElement($product);
91
        }
92
    }
93
94
    public function hasProduct(ProductInterface $product): bool
95
    {
96
        return $this->products->contains($product);
97
    }
98
99
    public function resetSlot(): void
100
    {
101
        $this->products->clear();
102
    }
103
104
    public function isPresentationSlot(): bool
105
    {
106
        if (null === $this->bundle) {
107
            return false;
108
        }
109
        return $this->bundle->getPresentationSlot() === $this;
110
    }
111
}
112