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
Pull Request — master (#74)
by
unknown
01:40
created

Activatable::isExactActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Menu\Traits;
4
5
use Spatie\Url\Url;
6
use Spatie\Menu\ActiveUrlChecker;
7
use Spatie\Menu\ExactUrlChecker;
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
        ExactUrlChecker::check($this->url, $url, $root)
97
            ? $this->setExactActive()
98
            : $this->setExactActive(false);
99
    }
100
101
    /**
102
     * Set if current Activatable should be marked as an exact url match
103
     *
104
     * @param bool $exactActive
105
     *
106
     * @return $this
107
     */
108
    public function setExactActive(bool $exactActive = true)
109
    {
110
        $this->exactActive = $exactActive;
0 ignored issues
show
Bug introduced by
The property exactActive does not seem to exist. Did you mean active?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
111
112
        return $this;
113
    }
114
115
    /**
116
     * Check if current Activatable is marked as an exact url match
117
     *
118
     * @return bool
119
     */
120
    public function isExactActive(): bool
121
    {
122
        return $this->exactActive;
0 ignored issues
show
Bug introduced by
The property exactActive does not seem to exist. Did you mean active?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
123
    }
124
}
125