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.
Completed
Push — master ( a34f50...45667e )
by Luis Ramón
02:54
created

MenuBuilderChain::getMenu()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 3
eloc 18
nc 3
nop 0
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
        return $this->getSubmenuItemByRouteName($root, $name);
0 ignored issues
show
Security Bug introduced by
It seems like $root defined by reset($menu) on line 104 can also be of type false; however, AppBundle\Service\MenuBu...ubmenuItemByRouteName() does only seem to accept object<AppBundle\Menu\MenuItem>, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
107
    }
108
109
    public function clearCache()
110
    {
111
        $this->menuCache = null;
112
    }
113
}
114