Completed
Pull Request — master (#15)
by Emanuele
14:44
created

Feature   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 176
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 18
c 5
b 1
f 0
lcom 2
cbo 1
dl 0
loc 176
ccs 27
cts 36
cp 0.75
rs 10

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getRole() 0 4 1
A getChildren() 0 4 1
A __toString() 0 4 1
A getId() 0 4 1
A getParent() 0 4 1
A setEnabled() 0 4 1
A getEnabled() 0 4 1
A setRole() 0 4 1
A getParentRole() 0 4 2
A isEnabled() 0 4 3
A setParent() 0 4 1
A addFeature() 0 4 1
A __construct() 0 4 1
A setName() 0 4 1
A getName() 0 4 1
1
<?php
2
3
namespace Ae\FeatureBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * Feature entity.
10
 *
11
 * @ORM\Table(name="application_feature")
12
 * @ORM\Entity
13
 */
14
class Feature
15
{
16
    /**
17
     * @var int
18
     *
19
     * @ORM\Column(type="integer")
20
     * @ORM\Id
21
     * @ORM\GeneratedValue(strategy="AUTO")
22
     */
23
    private $id;
24
25
    /**
26
     * @var string
27
     *
28
     * @ORM\Column(length=250)
29
     */
30
    private $name;
31
32
    /**
33
     * @var bool
34
     *
35
     * @ORM\Column(type="boolean")
36
     */
37
    private $enabled = false;
38
39
    /**
40
     * @var string
41
     *
42
     * @ORM\Column(type="text", nullable=true)
43
     */
44
    private $role;
45
46
    /**
47
     * @var ArrayCollection
48
     *
49
     * @ORM\OneToMany(targetEntity="Feature", mappedBy="parent")
50
     */
51
    private $children;
52
53
    /**
54
     * @var Feature
55
     *
56
     * @ORM\ManyToOne(targetEntity="Feature", inversedBy="children", cascade={"persist", "remove"})
57
     */
58
    private $parent;
59
60 8
    public function __construct()
61
    {
62 8
        $this->children = new ArrayCollection();
63 8
    }
64
65
    public function __toString()
66
    {
67
        return $this->getName();
68
    }
69
70
    /**
71
     * Get id.
72
     *
73
     * @return int
74
     */
75
    public function getId()
76
    {
77
        return $this->id;
78
    }
79
80
    /**
81
     * Set parent.
82
     *
83
     * @param Feature $parent
84
     */
85 4
    public function setParent(Feature $parent)
86
    {
87 4
        $this->parent = $parent;
88 4
    }
89
90
    /**
91
     * Get parent.
92
     *
93
     * @return Feature
94
     */
95 6
    public function getParent()
96
    {
97 6
        return $this->parent;
98
    }
99
100
    /**
101
     * Set name.
102
     *
103
     * @param string $name
104
     */
105
    public function setName($name)
106
    {
107
        $this->name = $name;
108
    }
109
110
    /**
111
     * Get name.
112
     *
113
     * @return string
114
     */
115
    public function getName()
116
    {
117
        return $this->name;
118
    }
119
120
    /**
121
     * Set enabled.
122
     *
123
     * @param bool $enabled
124
     */
125 3
    public function setEnabled($enabled)
126
    {
127 3
        $this->enabled = $enabled;
128 3
    }
129
130
    /**
131
     * Get enabled.
132
     *
133
     * @return bool
134
     */
135 4
    public function getEnabled()
136
    {
137 4
        return $this->enabled;
138
    }
139
140
    /**
141
     * Set role.
142
     *
143
     * @param string $role
144
     */
145 1
    public function setRole($role)
146
    {
147 1
        $this->role = $role;
148 1
    }
149
150
    /**
151
     * Get role.
152
     *
153
     * @return string
154
     */
155 1
    public function getRole()
156
    {
157 1
        return $this->role;
158
    }
159
160 2
    public function getParentRole()
161
    {
162 2
        return $this->getParent() ? $this->getParent()->getRole() : null;
163
    }
164
165
    /**
166
     * Add children.
167
     *
168
     * @param Feature $children
169
     */
170 1
    public function addFeature(Feature $children)
171
    {
172 1
        $this->children[] = $children;
173 1
    }
174
175
    /**
176
     * Get children.
177
     *
178
     * @return ArrayCollection
179
     */
180 1
    public function getChildren()
181
    {
182 1
        return $this->children;
183
    }
184
185 4
    public function isEnabled()
186
    {
187 4
        return $this->getEnabled() && ($this->getParent() ? $this->getParent()->getEnabled() : true);
188
    }
189
}
190