ECommerceCategory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\Models\ECommerce;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
7
/**
8
 * ECommerceCategory
9
 * Represents a tag applied on particular products.
10
 *
11
 * @author Giorgio Sironi
12
 */
13
class ECommerceCategory
14
{
15
    /**
16
     */
17
    private $id;
18
19
    /**
20
     */
21
    private $name;
22
23
    /**
24
     */
25
    private $products;
26
27
    /**
28
     */
29
    private $children;
30
31
    /**
32
     */
33
    private $parent;
34
35
    public function __construct()
36
    {
37
        $this->products = new ArrayCollection();
38
        $this->children = new ArrayCollection();
39
    }
40
41
    public function getId()
42
    {
43
        return $this->id;
44
    }
45
46
    public function getName()
47
    {
48
        return $this->name;
49
    }
50
51
    public function setName($name)
52
    {
53
        $this->name = $name;
54
    }
55
56
    public function addProduct(ECommerceProduct $product)
57
    {
58
        if (!$this->products->contains($product)) {
59
            $this->products[] = $product;
60
            $product->addCategory($this);
61
        }
62
    }
63
64
    public function removeProduct(ECommerceProduct $product)
65
    {
66
        $removed = $this->products->removeElement($product);
67
        if ($removed) {
68
            $product->removeCategory($this);
69
        }
70
    }
71
72
    public function getProducts()
73
    {
74
        return $this->products;
75
    }
76
77
    private function setParent(ECommerceCategory $parent)
78
    {
79
        $this->parent = $parent;
80
    }
81
82
    public function getChildren()
83
    {
84
        return $this->children;
85
    }
86
87
    public function getParent()
88
    {
89
        return $this->parent;
90
    }
91
92
    public function addChild(ECommerceCategory $child)
93
    {
94
        $this->children[] = $child;
95
        $child->setParent($this);
96
    }
97
98
    /** does not set the owning side. */
99
    public function brokenAddChild(ECommerceCategory $child)
100
    {
101
        $this->children[] = $child;
102
    }
103
104
105
    public function removeChild(ECommerceCategory $child)
106
    {
107
        $removed = $this->children->removeElement($child);
108
        if ($removed) {
109
            $child->removeParent();
110
        }
111
    }
112
113
    private function removeParent()
114
    {
115
        $this->parent = null;
116
    }
117
}
118