Passed
Pull Request — master (#181)
by Mathieu
03:28
created

Product::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zenstruck\Foundry\Tests\Fixtures\Entity\Cascade;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
9
/**
10
 * @ORM\Entity
11
 * @ORM\Table(name="product_cascade")
12
 */
13
class Product
14
{
15
    /**
16
     * @ORM\Id
17
     * @ORM\GeneratedValue
18
     * @ORM\Column(type="integer")
19
     */
20
    private $id;
21
22
    /**
23
     * @ORM\Column(type="string", length=255)
24
     */
25
    private $name;
26
27
    /**
28
     * @ORM\ManyToOne(targetEntity=Brand::class, inversedBy="products", cascade={"persist"})
29
     */
30
    private $brand;
31
32
    /**
33
     * @ORM\OneToMany(targetEntity=Variant::class, mappedBy="product", cascade={"persist"})
34
     */
35
    private $variants;
36
37
    /**
38
     * @ORM\ManyToMany(targetEntity=Category::class, mappedBy="products", cascade={"persist"})
39
     */
40
    private $categories;
41
42
    /**
43
     * @ORM\ManyToMany(targetEntity=Tag::class, inversedBy="products", cascade={"persist"})
44
     */
45
    private $tags;
46
47
    /**
48
     * @ORM\OneToOne(targetEntity=Review::class, mappedBy="product", cascade={"persist"})
49
     */
50
    private $review;
51
52
    public function __construct()
53
    {
54
        $this->variants = new ArrayCollection();
55
        $this->categories = new ArrayCollection();
56
        $this->tags = new ArrayCollection();
57
    }
58
59
    public function getId(): ?int
60
    {
61
        return $this->id;
62
    }
63
64
    public function getPrePersistedId(): ?int
65
    {
66
        return $this->prePersistedId;
67
    }
68
69
    public function setPrePersistedId(?int $prePersistedId): void
70
    {
71
        $this->prePersistedId = $prePersistedId;
0 ignored issues
show
Bug Best Practice introduced by
The property prePersistedId does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
72
    }
73
74
    public function getName(): ?string
75
    {
76
        return $this->name;
77
    }
78
79
    public function setName(?string $name): void
80
    {
81
        $this->name = $name;
82
    }
83
84
    public function getBrand(): Brand
85
    {
86
        return $this->brand;
87
    }
88
89
    public function setBrand(Brand $brand): void
90
    {
91
        $this->brand = $brand;
92
    }
93
94
    public function getReview(): Review
95
    {
96
        return $this->review;
97
    }
98
99
    public function setReview(Review $review): void
100
    {
101
        $this->review = $review;
102
    }
103
104
    public function getVariants(): Collection
105
    {
106
        return $this->variants;
107
    }
108
109
    public function addVariant(Variant $variant): void
110
    {
111
        if (!$this->variants->contains($variant)) {
112
            $this->variants[] = $variant;
113
            $variant->setProduct($this);
114
        }
115
    }
116
117
    public function removeVariant(Variant $variant): void
118
    {
119
        if ($this->variants->contains($variant)) {
120
            $this->variants->removeElement($variant);
121
        }
122
    }
123
124
    public function getCategories(): Collection
125
    {
126
        return $this->categories;
127
    }
128
129
    public function addCategory(Category $category): void
130
    {
131
        if (!$this->categories->contains($category)) {
132
            $this->categories[] = $category;
133
        }
134
    }
135
136
    public function removeCategory(Category $category): void
137
    {
138
        if ($this->categories->contains($category)) {
139
            $this->categories->removeElement($category);
140
        }
141
    }
142
143
    public function getTags(): Collection
144
    {
145
        return $this->tags;
146
    }
147
148
    public function addTag(Tag $tag): void
149
    {
150
        if (!$this->tags->contains($tag)) {
151
            $this->tags[] = $tag;
152
        }
153
    }
154
155
    public function removeTag(Tag $tag): void
156
    {
157
        if ($this->tags->contains($tag)) {
158
            $this->tags->removeElement($tag);
159
        }
160
    }
161
}
162