Passed
Push — master ( a2983d...01499e )
by Carlo
40s queued 10s
created

Feature::getDescription()   A

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