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

Breadcrumbs::contain()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Marky
5
 * Date: 04/01/2018
6
 * Time: 01:28
7
 */
8
9
namespace App\Classes;
10
11
use Illuminate\Http\Request;
12
use Illuminate\Support\Collection;
13
14
/**
15
 * Class Breadcrumbs
16
 *
17
 * @package App\Classes
18
 */
19
class Breadcrumbs
20
{
21
22
    /**
23
     * A collection of crumbs.
24
     *
25
     * @var Collection
26
     */
27
    protected $collection;
28
29
    /**
30
     * Breadcrumbs constructor.
31
     * @param Collection $collection
32
     */
33
    public function __construct(Collection $collection)
34
    {
35
        $this->collection = $collection;
36
    }
37
38
    /**
39
     * @param string $title
40
     * @param string $path
41
     * @return bool
42
     */
43
    public function addCrumb(string $title, string $path)
44
    {
45
        $crumb = new \stdClass();
46
        $crumb->title = $this->filter($title);
47
        $crumb->path = url($path);
48
49
        $this->collection->push($crumb);
50
51
        return true;
52
    }
53
54
    /**
55
     * @param string $title
56
     * @return string
57
     */
58
    public function filter(string $title)
59
    {
60
        return ucwords(str_replace(['_', '-'], [' ', ' '], $title));
61
    }
62
63
    /**
64
     * @return Collection
65
     */
66
    public function crumbs()
67
    {
68
        return $this->collection;
69
    }
70
71
    /**
72
     * @param string $name
73
     * @param int $position
74
     * @return bool
75
     */
76
    public function contain(string $name, int $position)
77
    {
78
        if ($this->collection->has($position) == false)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
79
            return false;
80
81
        return $this->collection->get($position)->title == $this->filter($name);
82
    }
83
84
    /**
85
     * @param int $integer
86
     * @return bool
87
     */
88
    public function hasCount(int $integer)
89
    {
90
        return $this->collection->count() == $integer;
91
    }
92
93
    /**
94
     * @param int $count
95
     * @return $this
96
     */
97
    public function limit(int $count)
98
    {
99
        $collection = new Collection;
100
101
        for ($i = 0; $i < $count; $i++)
102
        {
103
            if ($this->collection->has($i)) {
104
                $collection->push($this->collection->get($i));
105
            }
106
        }
107
108
        $this->collection = $collection;
109
110
        return $this;
111
    }
112
113
    /**
114
     * @return Breadcrumbs
115
     */
116
    public static function fromCurrentRoute()
117
    {
118
        /** @var Breadcrumbs $instance */
119
        $instance = app(self::class);
120
121
        /** @var array $routes */
122
        $routes = explode('/', app(Request::class)->getRequestUri());
123
124
        $urlPath = url(array_pull($routes, 0));
125
126
        // Add the home array.
127
        $instance->addCrumb('Home', $urlPath);
0 ignored issues
show
Bug introduced by
It seems like $urlPath defined by url(array_pull($routes, 0)) on line 124 can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, App\Classes\Breadcrumbs::addCrumb() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
128
129
        foreach ($routes as $route)
130
        {
131
            $urlPath = $urlPath . '/' . $route;
132
133
            $instance->addCrumb($route, $urlPath);
134
        }
135
136
        return $instance;
137
    }
138
139
}