Completed
Pull Request — master (#34)
by
unknown
05:48
created

ProductBundle::setProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace solutionDrive\SyliusProductBundlesPlugin\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Sylius\Component\Core\Model\ProductInterface;
10
11
class ProductBundle implements ProductBundleInterface
12
{
13
    /** @var int */
14
    private $id;
15
16
    /** @var ProductBundleSlotInterface[]|Collection|ArrayCollection */
17
    private $slots;
18
19
    /** @var ProductBundleSlotInterface|null */
20
    private $presentationSlot;
21
22
    /** @var ProductInterface|null */
23
    private $product;
24
25
    /**
26
     * ProductBundle constructor.
27
     */
28
    public function __construct()
29
    {
30
        $this->slots = new ArrayCollection();
31
    }
32
33
    /**
34
     * @return int
35
     */
36
    public function getId(): ?int
37
    {
38
        return $this->id;
39
    }
40
41
    /**
42
     * @param ProductBundleSlotInterface $slot
43
     */
44
    public function addSlot(ProductBundleSlotInterface $slot): void
45
    {
46
        if (!$this->slots->contains($slot)) {
47
            $slot->setBundle($this);
48
            $this->slots->add($slot);
49
        }
50
    }
51
52
    /**
53
     * @param ProductBundleSlotInterface $slot
54
     */
55
    public function removeSlot(ProductBundleSlotInterface $slot): void
56
    {
57
        if ($this->slots->contains($slot)) {
58
            $this->slots->removeElement($slot);
59
            $slot->setBundle(null);
60
        }
61
    }
62
63
    /**
64
     * @return ProductBundleSlotInterface[]|Collection|ArrayCollection
65
     */
66
    public function getSlots(): Collection
67
    {
68
        return $this->slots;
69
    }
70
71
    /**
72
     * @return ProductInterface
73
     */
74
    public function getProduct(): ?ProductInterface
75
    {
76
        return $this->product;
77
    }
78
79
    /**
80
     * @param ProductInterface $product
81
     */
82
    public function setProduct(ProductInterface $product): void
83
    {
84
        $this->product = $product;
85
    }
86
87
    public function getProductId(): ?int
88
    {
89
        if (null === $this->product) {
90
            return null;
91
        }
92
93
        return $this->product->getId();
94
    }
95
96
    public function setPresentationSlot(ProductBundleSlotInterface $slot): void
97
    {
98
        $this->presentationSlot = $slot;
99
    }
100
101
    public function getPresentationSlot(): ?ProductBundleSlotInterface
102
    {
103
        return $this->presentationSlot;
104
    }
105
}
106