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 ( d93276...d734fb )
by Sebastian
02:26
created

Activatable::determineActiveForUrl()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 2
1
<?php
2
3
namespace Spatie\Menu\Traits;
4
5
use Spatie\Menu\ActiveUrlChecker;
6
use Spatie\Menu\Helpers\Str;
7
use Spatie\Url\Url;
8
9
/**
10
 * Expects an `$active` property on the class.
11
 *
12
 * @property string $url
13
 */
14
trait Activatable
15
{
16
    /**
17
     * @return bool
18
     */
19
    public function isActive(): bool
20
    {
21
        return $this->active;
0 ignored issues
show
Bug introduced by
The property active does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
    }
23
24
    /**
25
     * @param bool|callable $active
26
     *
27
     * @return $this
28
     */
29
    public function setActive($active = true)
30
    {
31
        if (is_callable($active)) {
32
            $this->active = $active($this);
33
34
            return $this;
35
        }
36
37
        $this->active = (bool) $active;
38
39
        return $this;
40
    }
41
42
    /**
43
     * @return $this
44
     */
45
    public function setInactive()
46
    {
47
        $this->active = false;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return string|null
54
     */
55
    public function url()
56
    {
57
        return $this->url;
58
    }
59
60
    /**
61
     * @return bool
62
     */
63
    public function hasUrl(): bool
64
    {
65
        return ! is_null($this->url);
66
    }
67
68
    /**
69
     * @param string|null $url
70
     *
71
     * @return $this
72
     */
73
    public function setUrl($url)
74
    {
75
        $this->url = $url;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @param string $url
82
     * @param string $root
83
     *
84
     * @return $this
85
     */
86
    public function determineActiveForUrl(string $url, string $root = '/')
87
    {
88
        if (! $this->hasUrl()) {
89
            return;
90
        }
91
92
        ActiveUrlChecker::check($this->url, $url, $root)
93
            ? $this->setActive()
94
            : $this->setInactive();
95
    }
96
}
97