Completed
Pull Request — master (#77)
by Mikołaj
01:13
created

ProductableTrait::hasProduct()   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
/**
4
 * This file was created by the developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
namespace BitBag\CmsPlugin\Entity;
12
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Sylius\Component\Core\Model\ProductInterface;
16
17
/**
18
 * @author Mikołaj Król <[email protected]>
19
 */
20
trait ProductableTrait
21
{
22
    /**
23
     * @var Collection|ProductInterface[]
24
     */
25
    protected $products;
26
27
    public function initializeProductsCollection(): void
28
    {
29
        $this->products = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\C...odel\ProductInterface>> of property $products.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
    }
31
32
    /**
33
     * @return Collection|ProductInterface[]
34
     */
35
    public function getProducts(): Collection
36
    {
37
        return $this->products;
38
    }
39
40
    /**
41
     * @param ProductInterface $product
42
     *
43
     * @return bool
44
     */
45
    public function hasProduct(ProductInterface $product): bool
46
    {
47
        return $this->products->contains($product);
48
    }
49
50
    /**
51
     * @param ProductInterface $product
52
     */
53
    public function addProduct(ProductInterface $product): void
54
    {
55
        $this->products->add($product);
56
    }
57
58
    /**
59
     * @param ProductInterface $product
60
     */
61
    public function removeProduct(ProductInterface $product): void
62
    {
63
        if (true === $this->hasProduct($product)) {
64
            $this->products->removeElement($product);
65
        }
66
    }
67
}
68