Completed
Push — master ( d81c19...f57266 )
by Kamil
20s
created

Component/Product/Model/ProductAssociation.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sylius\Component\Product\Model;
15
16
use Doctrine\Common\Collections\ArrayCollection;
17
use Doctrine\Common\Collections\Collection;
18
use Sylius\Component\Resource\Model\TimestampableTrait;
19
20
class ProductAssociation implements ProductAssociationInterface
21
{
22
    use TimestampableTrait;
23
24
    /**
25
     * @var mixed
26
     */
27
    protected $id;
28
29
    /**
30
     * @var ProductAssociationTypeInterface
31
     */
32
    protected $type;
33
34
    /**
35
     * @var ProductInterface
36
     */
37
    protected $owner;
38
39
    /**
40
     * @var Collection|ProductInterface[]
41
     */
42
    protected $associatedProducts;
43
44
    public function __construct()
45
    {
46
        $this->createdAt = new \DateTime();
47
        $this->updatedAt = new \DateTime();
48
        $this->associatedProducts = 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 $associatedProducts.

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...
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getId()
55
    {
56
        return $this->id;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getType(): ?ProductAssociationTypeInterface
63
    {
64
        return $this->type;
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function setType(?ProductAssociationTypeInterface $type): void
71
    {
72
        $this->type = $type;
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function getOwner(): ?ProductInterface
79
    {
80
        return $this->owner;
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function setOwner(?ProductInterface $owner): void
87
    {
88
        $this->owner = $owner;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function getAssociatedProducts(): Collection
95
    {
96
        return $this->associatedProducts;
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function hasAssociatedProduct(ProductInterface $product): bool
103
    {
104
        return $this->associatedProducts->contains($product);
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function addAssociatedProduct(ProductInterface $product): void
111
    {
112
        if (!$this->hasAssociatedProduct($product)) {
113
            $this->associatedProducts->add($product);
114
        }
115
    }
116
117
    /**
118
     * {@inheritdoc}
119
     */
120
    public function removeAssociatedProduct(ProductInterface $product): void
121
    {
122
        if ($this->hasAssociatedProduct($product)) {
123
            $this->associatedProducts->removeElement($product);
124
        }
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function clearAssociatedProducts(): void
131
    {
132
        $this->associatedProducts->clear();
133
    }
134
}
135