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 ( 5c7169...b34131 )
by Mark
08:19 queued 05:45
created

Navigation::generateNav()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Marky
5
 * Date: 30/12/2017
6
 * Time: 18:51.
7
 */
8
9
namespace App\Classes\Library\PageLoader;
10
11
use App\Model\Menu;
12
use Illuminate\Support\Collection;
13
14
/**
15
 * Class Navigation.
16
 */
17
class Navigation
18
{
19
    /**
20
     * @var array
21
     */
22
    private $routes = [];
23
24
    /**
25
     * @var Collection
26
     */
27
    public $collection = [];
28
29
    /**
30
     * Navigation constructor.
31
     *
32
     * @param Collection $repository
33
     */
34
    public function __construct(Collection $repository)
35
    {
36
        $this->routes = $this->splitRoutes();
37
38
        $this->collection = $this->generateNav($repository->keyBy('title'));
39
    }
40
41
    /**
42
     * @param Collection $repository
43
     * @return Collection
44
     */
45
    protected function generateNav(Collection $repository)
46
    {
47
        $collection = new Collection;
48
49
        /** @var Menu $item */
50
        foreach ($repository as $item) {
51
            $collection->put($item->title, $parent = $this->makeNavItem($item));
52
53
            /* @var NavItem $parent */
54
            foreach ($item->children as $new) {
55
                $parent->addChild($this->makeNavItem($new));
0 ignored issues
show
Documentation introduced by
$this->makeNavItem($new) is of type object<App\Classes\Library\PageLoader\NavItem>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
            }
57
        }
58
59
        return $this->collection = $collection;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    private function splitRoutes()
66
    {
67
        $path = app('request')->path();
68
69
        if ($path == '/') {
70
            return $this->routes = ['index'];
71
        }
72
73
        return explode('/', $path);
74
    }
75
76
    /**
77
     * @default $menu->page->slug == currentURI() ? true : false;
78
     * @param string $string
79
     * @return bool
80
     */
81
    public function isActiveTitle(string $string)
82
    {
83
        return in_array(str_slug($string), $this->routes);
84
    }
85
86
    /**
87
     * @param $menu
88
     * @return NavItem
89
     */
90
    protected function makeNavItem(Menu $menu): NavItem
91
    {
92
        return new NavItem($menu, $this->isActiveTitle($menu->page->slug));
93
    }
94
}
95