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 ( 70e47f...dda101 )
by Mark
07:55
created

Navigation::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 11
rs 9.4285
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\Coordinators;
10
11
use App\Model\Menu;
12
use App\Model\Page;
13
use App\Classes\Breadcrumbs;
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
        if ($this->navigation->isNotEmpty())
49
        {
50
            $this->lookupCurrentMenu();
51
        }
52
    }
53
54
    /**
55
     * @param Menu $menu
56
     * @return bool
57
     */
58
    private function isCurrent(Menu $menu)
59
    {
60
        return $this->page->route() == $menu->link->url();
61
    }
62
63
    /**
64
     * Activate, the current menu.
65
     */
66
    private function lookupCurrentMenu()
67
    {
68
        foreach ($this->navigation as $menu) {
0 ignored issues
show
Bug introduced by
The expression $this->navigation of type object<App\Classes\Libra...oordinators\Navigation> is not traversable.
Loading history...
69
            foreach ($menu->children as $submenu) {
70
                if ($this->isCurrent($submenu)) {
71
                    $this->setActiveMenu($submenu);
72
73
                    break;
74
                }
75
            }
76
77
            if ($this->hasActiveMenu()) {
78
                $menu->active = true;
79
80
                break;
81
            } elseif ($this->isCurrent($menu)) {
82
                $this->setActiveMenu($menu);
83
84
                break;
85
            }
86
        }
87
    }
88
89
    public function setActiveMenu(Menu $menu)
90
    {
91
        $this->activeMenu = $menu;
92
93
        return $menu->active = true;
94
    }
95
96
    /**
97
     * @return bool
98
     */
99
    private function hasActiveMenu()
100
    {
101
        return $this->activeMenu ? true : false;
102
    }
103
104
    /**
105
     * Main menu construction.
106
     */
107
    public function main()
108
    {
109
        return $this->navigation;
110
    }
111
112
    /**
113
     * @return Menu|array
114
     */
115
    public function sidebar()
116
    {
117
        if ($this->hasActiveMenu()) {
118
            if ($this->activeMenu->parent) {
119
                $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...oordinators\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...
120
121
                return $menu->children;
122
            }
123
124
            $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...oordinators\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...
125
126
            return $menu->children;
127
        }
128
129
        return [];
130
    }
131
132
    /**
133
     * @return bool
134
     */
135
    public function hasSidebar()
136
    {
137
        return count($this->sidebar()) > 0 ? true : false;
138
    }
139
140
    /**
141
     * @return \Illuminate\Support\Collection
142
     */
143
    public function breadcrumbs()
144
    {
145
        return Breadcrumbs::fromCurrentRoute()->crumbs();
146
    }
147
}
148