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

Product::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
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;
0 ignored issues
show
introduced by
The private property $id is not used, and could be removed.
Loading history...
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 getName(): ?string
60
    {
61
        return $this->name;
62
    }
63
64
    public function setName(?string $name): void
65
    {
66
        $this->name = $name;
67
    }
68
69
    public function getBrand(): Brand
70
    {
71
        return $this->brand;
72
    }
73
74
    public function setBrand(Brand $brand): void
75
    {
76
        $this->brand = $brand;
77
    }
78
79
    public function getReview(): Review
80
    {
81
        return $this->review;
82
    }
83
84
    public function setReview(Review $review): void
85
    {
86
        $this->review = $review;
87
    }
88
89
    public function getVariants(): Collection
90
    {
91
        return $this->variants;
92
    }
93
94
    public function addVariant(Variant $variant): void
95
    {
96
        if (!$this->variants->contains($variant)) {
97
            $this->variants[] = $variant;
98
            $variant->setProduct($this);
99
        }
100
    }
101
102
    public function removeVariant(Variant $variant): void
103
    {
104
        if ($this->variants->contains($variant)) {
105
            $this->variants->removeElement($variant);
106
        }
107
    }
108
109
    public function getCategories(): Collection
110
    {
111
        return $this->categories;
112
    }
113
114
    public function addCategory(Category $category): void
115
    {
116
        if (!$this->categories->contains($category)) {
117
            $this->categories[] = $category;
118
        }
119
    }
120
121
    public function removeCategory(Category $category): void
122
    {
123
        if ($this->categories->contains($category)) {
124
            $this->categories->removeElement($category);
125
        }
126
    }
127
128
    public function getTags(): Collection
129
    {
130
        return $this->tags;
131
    }
132
133
    public function addTag(Tag $tag): void
134
    {
135
        if (!$this->tags->contains($tag)) {
136
            $this->tags[] = $tag;
137
        }
138
    }
139
140
    public function removeTag(Tag $tag): void
141
    {
142
        if ($this->tags->contains($tag)) {
143
            $this->tags->removeElement($tag);
144
        }
145
    }
146
}
147