Completed
Push — master ( ea0a23...156714 )
by Joachim
12s queued 11s
created

ProductsAwareTrait::hasProduct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBrandPlugin\Model;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
10
trait ProductsAwareTrait
11
{
12
    /**
13
     * @var Collection|ProductInterface[]
14
     */
15
    protected $products;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    public function __construct()
21
    {
22
        $this->products = new ArrayCollection();
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function hasProducts(): bool
29
    {
30
        return $this->products->count() > 0;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getProducts(): Collection
37
    {
38
        return $this->products;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function hasProduct(ProductInterface $product): bool
45
    {
46
        return $this->products->contains($product);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    abstract public function addProduct(ProductInterface $product): void;
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    abstract public function removeProduct(ProductInterface $product): void;
58
}
59