Completed
Push — remove-content-bundle ( 201341 )
by Kamil
34:43
created

ProductAssociation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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
namespace Sylius\Component\Product\Model;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use Sylius\Component\Resource\Model\TimestampableTrait;
17
18
/**
19
 * @author Leszek Prabucki <[email protected]>
20
 * @author Łukasz Chruściel <[email protected]>
21
 */
22
class ProductAssociation implements ProductAssociationInterface
23
{
24
    use TimestampableTrait;
25
26
    /**
27
     * @var mixed
28
     */
29
    protected $id;
30
31
    /**
32
     * @var ProductAssociationTypeInterface
33
     */
34
    protected $type;
35
36
    /**
37
     * @var ProductInterface
38
     */
39
    protected $owner;
40
41
    /**
42
     * @var Collection|ProductInterface[]
43
     */
44
    protected $associatedProducts;
45
46
    public function __construct()
47
    {
48
        $this->createdAt = new \DateTime();
49
        $this->updatedAt = new \DateTime();
50
        $this->associatedProducts = new ArrayCollection();
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getId()
57
    {
58
        return $this->id;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getType()
65
    {
66
        return $this->type;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function setType(ProductAssociationTypeInterface $type)
73
    {
74
        $this->type = $type;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function getOwner()
81
    {
82
        return $this->owner;
83
    }
84
85
    /**
86
     * {@inheritdoc}
87
     */
88
    public function setOwner(ProductInterface $owner = null)
89
    {
90
        $this->owner = $owner;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function getAssociatedProducts()
97
    {
98
        return $this->associatedProducts;
99
    }
100
101
    /**
102
     * {@inheritdoc}
103
     */
104
    public function hasAssociatedProduct(ProductInterface $product)
105
    {
106
        return $this->associatedProducts->contains($product);
107
    }
108
109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function addAssociatedProduct(ProductInterface $product)
113
    {
114
        if (!$this->hasAssociatedProduct($product)) {
115
            $this->associatedProducts->add($product);
116
        }
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122
    public function removeAssociatedProduct(ProductInterface $product)
123
    {
124
        if ($this->hasAssociatedProduct($product)) {
125
            $this->associatedProducts->removeElement($product);
126
        }
127
    }
128
}
129