ProductsAwareTrait::getProducts()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Entity;
12
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Sylius\Component\Core\Model\ProductInterface;
16
17
trait ProductsAwareTrait
18
{
19
    /** @var Collection|ProductInterface[] */
20
    protected $products;
21
22
    public function initializeProductsCollection(): void
23
    {
24
        $this->products = new ArrayCollection();
25
    }
26
27
    public function getProducts(): Collection
28
    {
29
        return $this->products;
30
    }
31
32
    public function hasProduct(ProductInterface $product): bool
33
    {
34
        return $this->products->contains($product);
35
    }
36
37
    public function addProduct(ProductInterface $product): void
38
    {
39
        if (false === $this->hasProduct($product)) {
40
            $this->products->add($product);
41
        }
42
    }
43
44
    public function removeProduct(ProductInterface $product): void
45
    {
46
        if (true === $this->hasProduct($product)) {
47
            $this->products->removeElement($product);
48
        }
49
    }
50
}
51