Completed
Pull Request — master (#6185)
by Ilya
09:34
created

Category::addProduct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Doctrine\Tests\Models\AivusTest;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
8
/**
9
 * @Entity
10
 * @Table(name="categories")
11
 */
12
class Category
13
{
14
    /**
15
     * @Column(type="integer")
16
     * @Id
17
     * @GeneratedValue
18
     *
19
     * @var int
20
     */
21
    protected $id;
22
23
    /**
24
     * @ManyToMany(targetEntity="Product")
25
     * @JoinTable(name="category_to_products",
26
     *      joinColumns={@JoinColumn(name="category_id", referencedColumnName="id")},
27
     *      inverseJoinColumns={@JoinColumn(name="product_id", referencedColumnName="id", unique=true)}
28
     * )
29
     */
30
    protected $products;
31
32
    public function __construct()
33
    {
34
        $this->products = new ArrayCollection();
35
    }
36
37
    /**
38
     * @return int
39
     */
40
    public function getId()
41
    {
42
        return $this->id;
43
    }
44
45
    /**
46
     * @return Collection|Product[]
47
     */
48
    public function getProducts()
49
    {
50
        return $this->products;
51
    }
52
53
    /**
54
     * @param Product $product
55
     *
56
     * @return $this
57
     */
58
    public function addProduct(Product $product)
59
    {
60
        if (!$this->products->contains($product)) {
61
            $this->products->add($product);
62
        }
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param Product $product
69
     *
70
     * @return $this
71
     */
72
    public function removeProduct(Product $product)
73
    {
74
        if ($this->products->contains($product)) {
75
            $this->products->removeElement($product);
76
        }
77
78
        return $this;
79
    }
80
}
81