Feature::setRole()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
    /**
61
     * @var string|null
62
     *
63
     * @ORM\Column(nullable=true)
64
     */
65
    private $description;
66
67 12
    public function __construct()
68
    {
69 12
        $this->children = new ArrayCollection();
70 12
    }
71
72
    public function __toString()
73
    {
74
        return $this->getName();
75
    }
76
77
    /**
78
     * Get id.
79
     *
80
     * @return int
81
     */
82
    public function getId()
83
    {
84
        return $this->id;
85
    }
86
87
    /**
88
     * Set parent.
89
     */
90 6
    public function setParent(Feature $parent)
91
    {
92 6
        $this->parent = $parent;
93 6
    }
94
95
    /**
96
     * Get parent.
97
     *
98
     * @return Feature
99
     */
100 6
    public function getParent()
101
    {
102 6
        return $this->parent;
103
    }
104
105
    /**
106
     * Set name.
107
     *
108
     * @param string $name
109
     */
110
    public function setName($name)
111
    {
112
        $this->name = $name;
113
    }
114
115
    /**
116
     * Get name.
117
     *
118
     * @return string
119
     */
120
    public function getName()
121
    {
122
        return $this->name;
123
    }
124
125
    /**
126
     * Set enabled.
127
     *
128
     * @param bool $enabled
129
     */
130 3
    public function setEnabled($enabled)
131
    {
132 3
        $this->enabled = $enabled;
133 3
    }
134
135
    /**
136
     * Get enabled.
137
     *
138
     * @return bool
139
     */
140 4
    public function getEnabled()
141
    {
142 4
        return $this->enabled;
143
    }
144
145
    /**
146
     * Set role.
147
     *
148
     * @param string $role
149
     */
150 4
    public function setRole($role)
151
    {
152 4
        $this->role = $role;
153 4
    }
154
155
    /**
156
     * Get role.
157
     *
158
     * @return string
159
     */
160 1
    public function getRole()
161
    {
162 1
        return $this->role;
163
    }
164
165 3
    public function hasRole(): bool
166
    {
167 3
        return !empty($this->role);
168
    }
169
170 2
    public function hasParentRole(): bool
171
    {
172 2
        return $this->parent instanceof self && $this->parent->hasRole();
173
    }
174
175 1
    public function requiresRoleCheck(): bool
176
    {
177 1
        return $this->hasRole() || $this->hasParentRole();
178
    }
179
180 2
    public function getParentRole()
181
    {
182 2
        return $this->getParent() ? $this->getParent()->getRole() : null;
183
    }
184
185
    /**
186
     * Add children.
187
     */
188 1
    public function addFeature(Feature $children)
189
    {
190 1
        $this->children[] = $children;
191 1
    }
192
193
    /**
194
     * Get children.
195
     *
196
     * @return ArrayCollection
197
     */
198 1
    public function getChildren()
199
    {
200 1
        return $this->children;
201
    }
202
203 4
    public function isEnabled()
204
    {
205 4
        return $this->getEnabled() && ($this->getParent() ? $this->getParent()->getEnabled() : true);
206
    }
207
208
    /**
209
     * Get description.
210
     *
211
     * @return string|null
212
     */
213 1
    public function getDescription()
214
    {
215 1
        return $this->description;
216
    }
217
218
    /**
219
     * Set description.
220
     *
221
     * @param string|null $description
222
     */
223 1
    public function setDescription($description)
224
    {
225 1
        $this->description = $description;
226 1
    }
227
}
228