ProductsAwareTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 9
c 0
b 0
f 0
dl 0
loc 31
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getProducts() 0 3 1
A hasProduct() 0 3 1
A initializeProductsCollection() 0 3 1
A removeProduct() 0 4 2
A addProduct() 0 4 2
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