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.

MenuBuilderChain::getMenuItemByRouteName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
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\Service;
22
23
use AppBundle\Menu\MenuItem;
24
25
class MenuBuilderChain
26
{
27
    /**
28
     * @var MenuBuilderInterface[]
29
     */
30
    private $menuBuilders;
31
32
    /**
33
     * @var MenuItem[]|null
34
     */
35
    private $menuCache;
36
37
    public function __construct()
38
    {
39
        $this->menuBuilders = [];
40
        $this->menuCache = null;
41
    }
42
43
    public function addMenuBuilder(MenuBuilderInterface $menuBuilder)
44
    {
45
        $this->menuBuilders[$menuBuilder->getMenuPriority()] = $menuBuilder;
46
    }
47
48
    public function getChain()
49
    {
50
        return $this->menuBuilders;
51
    }
52
53
    public function getMenu()
54
    {
55
        if ($this->menuCache) {
56
            return $this->menuCache;
57
        }
58
59
        $menu = [];
60
61
        $mainItem = new MenuItem();
62
        $mainItem
63
            ->setName('frontpage')
64
            ->setRouteName('frontpage')
65
            ->setCaption('menu.frontpage')
66
            ->setDescription('menu.frontpage.detail')
67
            ->setColor('white')
68
            ->setIcon('home');
69
70
        $menu[] = $mainItem;
71
72
        ksort($this->menuBuilders);
73
74
        foreach ($this->menuBuilders as $menuBuilder) {
75
            $menuBuilder->updateMenu($menu);
76
        }
77
78
        $this->menuCache = $menu;
79
80
        return $menu;
81
    }
82
83
    public function getSubmenuItemByRouteName(MenuItem $submenu, $name)
84
    {
85
        if ($submenu->getRouteName() === $name) {
86
            return $submenu;
87
        }
88
89
        $children = $submenu->getChildren();
90
91
        foreach ($children as $item) {
92
            $result = $this->getSubmenuItemByRouteName($item, $name);
93
            if (null !== $result) {
94
                return $result;
95
            }
96
        }
97
98
        return null;
99
    }
100
101
    public function getMenuItemByRouteName($name)
102
    {
103
        $menu = $this->getMenu();
104
        $root = reset($menu);
105
106
        if (false === $root) {
107
            return null;
108
        }
109
110
        return $this->getSubmenuItemByRouteName($root, $name);
111
    }
112
113
    public function clearCache()
114
    {
115
        $this->menuCache = null;
116
    }
117
}
118