Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Push — master ( 7fd57f...ddf3cc )
by Mark
02:55
created

Navigation::lookupCurrentMenu()   B

Complexity

Conditions 6
Paths 10

Size

Total Lines 30
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 12
nc 10
nop 0
dl 0
loc 30
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Marky
5
 * Date: 31/12/2017
6
 * Time: 02:23.
7
 */
8
9
namespace App\Classes\Library\PageLoader\Cordinators;
10
11
use App\Classes\Breadcrumbs;
12
use App\Model\Menu;
13
use App\Model\Page;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, App\Classes\Library\PageLoader\Cordinators\Page.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
use Illuminate\Support\Collection;
15
16
/**
17
 * Class Collections.
18
 */
19
class Navigation
20
{
21
    /**
22
     * @var Page
23
     */
24
    private $page;
25
26
    /**
27
     * @var Navigation
28
     */
29
    private $navigation;
30
31
    /**
32
     * @var Menu
33
     */
34
    private $activeMenu;
35
36
    /**
37
     * Collections constructor.
38
     *
39
     * @param \App\Model\Page $page
40
     * @param Collection $navigation
41
     */
42
    public function __construct(Page $page, Collection $navigation)
43
    {
44
        $this->page = $page;
45
46
        $this->navigation = $navigation;
47
48
        $this->lookupCurrentMenu();
49
50
    }
51
52
    /**
53
     * @param Menu $menu
54
     * @return bool
55
     */
56
    private function isCurrent(Menu $menu)
57
    {
58
        return $this->page->route() == $menu->link->url();
59
    }
60
61
    /**
62
     * Activate, the current menu.
63
     */
64
    private function lookupCurrentMenu()
65
    {
66
        foreach($this->navigation as $menu)
0 ignored issues
show
Bug introduced by
The expression $this->navigation of type object<App\Classes\Libra...Cordinators\Navigation> is not traversable.
Loading history...
67
        {
68
            foreach ($menu->children as $submenu)
69
            {
70
                if ($this->isCurrent($submenu))
71
                {
72
                    $this->setActiveMenu($submenu);
73
74
                    break;
75
                }
76
            }
77
78
            if ($this->hasActiveMenu())
79
            {
80
                $menu->active = true;
81
82
                break;
83
            }
84
85
            else if ($this->isCurrent($menu))
86
            {
87
                $this->setActiveMenu($menu);
88
89
                break;
90
            }
91
92
        }
93
    }
94
95
    public function setActiveMenu(Menu $menu)
96
    {
97
        $this->activeMenu = $menu;
98
99
        return $menu->active = true;
100
    }
101
102
    /**
103
     * @return bool
104
     */
105
    private function hasActiveMenu()
106
    {
107
        return $this->activeMenu ? true : false;
108
    }
109
110
    /**
111
     * @return array
112
     */
113
    public function plugins()
114
    {
115
        return [];
116
    }
117
118
    /**
119
     * Main menu construction.
120
     */
121
    public function main()
122
    {
123
        return $this->navigation;
124
    }
125
126
    /**
127
     * @return Menu|array
128
     */
129
    public function sidebar()
130
    {
131
        if ($this->hasActiveMenu())
132
        {
133
            if ($this->activeMenu->parent)
134
            {
135
                $menu = $this->navigation->where('title', $this->activeMenu->parent->title)->first();
0 ignored issues
show
Bug introduced by
The method where() does not seem to exist on object<App\Classes\Libra...Cordinators\Navigation>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
136
137
                return $menu->children;
138
            }
139
140
            $menu = $this->navigation->where('title', $this->activeMenu->title)->first();
0 ignored issues
show
Bug introduced by
The method where() does not seem to exist on object<App\Classes\Libra...Cordinators\Navigation>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
141
142
            return $menu->children;
143
        }
144
145
        return [];
146
    }
147
148
    /**
149
     * @return bool
150
     */
151
    public function hasSidebar()
152
    {
153
        return false;
154
    }
155
156
    /**
157
     * @return \Illuminate\Support\Collection
158
     */
159
    public function breadcrumbs()
160
    {
161
        return Breadcrumbs::fromCurrentRoute()->crumbs();
162
    }
163
}
164