Completed
Pull Request — master (#95)
by
unknown
01:26
created

ProductsAwareTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 48
c 0
b 0
f 0
rs 10

5 Methods

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