GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MenuItem   A
last analyzed

Complexity

Total Complexity 23

Size/Duplication

Total Lines 257
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 23
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 257
rs 10

21 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A setName() 0 5 1
A getCaption() 0 4 1
A setCaption() 0 5 1
A getDescription() 0 4 1
A setDescription() 0 5 1
A getRouteName() 0 4 1
A setRouteName() 0 5 1
A getRouteParams() 0 4 1
A setRouteParams() 0 5 1
A getIcon() 0 4 1
A setIcon() 0 5 1
A getColor() 0 4 1
A setColor() 0 5 1
A getChildren() 0 4 1
A addChild() 0 11 2
A removeChild() 0 7 1
A getParent() 0 4 1
A setParent() 0 5 1
A getPath() 0 12 2
1
<?php
2
/*
3
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2016: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Menu;
22
23
class MenuItem
24
{
25
    const AT_THE_BEGINNING = 1;
26
    const AT_THE_END = 2;
27
28
    /**
29
     * @var string
30
     */
31
    protected $name;
32
33
    /**
34
     * @var string
35
     */
36
    protected $caption;
37
38
    /**
39
     * @var string
40
     */
41
    protected $description;
42
43
    /**
44
     * @var string
45
     */
46
    protected $routeName;
47
48
    /**
49
     * @var array
50
     */
51
    protected $routeParams = [];
52
53
    /**
54
     * @var string
55
     */
56
    protected $icon;
57
58
    /**
59
     * @var string
60
     */
61
    protected $color;
62
63
    /**
64
     * @var MenuItem[]
65
     */
66
    protected $children;
67
68
    /**
69
     * @var MenuItem|null
70
     */
71
    protected $parent;
72
73
    /**
74
     * MenuItem constructor
75
     */
76
    public function __construct()
77
    {
78
        $this->children = [];
79
        $this->parent = null;
80
    }
81
82
    /**
83
     * @return string
84
     */
85
    public function getName()
86
    {
87
        return $this->name;
88
    }
89
90
    /**
91
     * @param string $name
92
     * @return MenuItem
93
     */
94
    public function setName($name)
95
    {
96
        $this->name = $name;
97
        return $this;
98
    }
99
100
    /**
101
     * @return string
102
     */
103
    public function getCaption()
104
    {
105
        return $this->caption;
106
    }
107
108
    /**
109
     * @param string $caption
110
     * @return MenuItem
111
     */
112
    public function setCaption($caption)
113
    {
114
        $this->caption = $caption;
115
        return $this;
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function getDescription()
122
    {
123
        return $this->description;
124
    }
125
126
    /**
127
     * @param string $description
128
     * @return MenuItem
129
     */
130
    public function setDescription($description)
131
    {
132
        $this->description = $description;
133
        return $this;
134
    }
135
136
    /**
137
     * @return string
138
     */
139
    public function getRouteName()
140
    {
141
        return $this->routeName;
142
    }
143
144
    /**
145
     * @param string $routeName
146
     * @return MenuItem
147
     */
148
    public function setRouteName($routeName)
149
    {
150
        $this->routeName = $routeName;
151
        return $this;
152
    }
153
154
    /**
155
     * @return array
156
     */
157
    public function getRouteParams()
158
    {
159
        return $this->routeParams;
160
    }
161
162
    /**
163
     * @param array $routeParams
164
     * @return MenuItem
165
     */
166
    public function setRouteParams($routeParams)
167
    {
168
        $this->routeParams = $routeParams;
169
        return $this;
170
    }
171
172
    /**
173
     * @return string
174
     */
175
    public function getIcon()
176
    {
177
        return $this->icon;
178
    }
179
180
    /**
181
     * @param string $icon
182
     * @return MenuItem
183
     */
184
    public function setIcon($icon)
185
    {
186
        $this->icon = $icon;
187
        return $this;
188
    }
189
190
    /**
191
     * @return string
192
     */
193
    public function getColor()
194
    {
195
        return $this->color;
196
    }
197
198
    /**
199
     * @param string $color
200
     * @return MenuItem
201
     */
202
    public function setColor($color)
203
    {
204
        $this->color = $color;
205
        return $this;
206
    }
207
208
    /**
209
     * @return MenuItem[]
210
     */
211
    public function getChildren()
212
    {
213
        return $this->children;
214
    }
215
216
    /**
217
     * @param MenuItem $child
218
     * @return MenuItem
219
     */
220
    public function addChild(MenuItem $child, $where = self::AT_THE_END)
221
    {
222
        if ($where === self::AT_THE_END) {
223
            $this->children[] = $child;
224
        } else {
225
            array_unshift($this->children, $child);
226
        }
227
228
        $child->setParent($this);
229
        return $this;
230
    }
231
232
    /**
233
     * @param MenuItem $child
234
     * @return MenuItem
235
     */
236
    public function removeChild(MenuItem $child)
237
    {
238
        $this->children = array_filter($this->children, function(MenuItem $e) use ($child) {
239
            return $e !== $child;
240
        });
241
        return $this;
242
    }
243
244
    /**
245
     * @return MenuItem|null
246
     */
247
    public function getParent()
248
    {
249
        return $this->parent;
250
    }
251
252
    /**
253
     * @param MenuItem|null $parent
254
     * @return MenuItem
255
     */
256
    public function setParent(MenuItem $parent)
257
    {
258
        $this->parent = $parent;
259
        return $this;
260
    }
261
262
    /**
263
     * Devuelve la ruta del ítem hasta la raíz
264
     * 
265
     * @return MenuItem[]|null
266
     */
267
    public function getPath()
268
    {
269
        $path = [$this];
270
        $current = $this;
271
272
        while (null !== $current->getParent()) {
273
            array_unshift($path, $current->getParent());
274
            $current = $current->getParent();
275
        }
276
277
        return $path;
278
    }
279
}
280