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 ( f97fa9...d5dc5f )
by Sebastian
03:35
created

HasUrl   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 58
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A url() 0 4 1
A setUrl() 0 6 1
B determineActiveForUrl() 0 27 4
1
<?php
2
3
namespace Spatie\Menu\Traits;
4
5
use Spatie\Menu\Helpers\Str;
6
use Spatie\Url\Url;
7
8
/**
9
 * Expects a `$url` property on the class.
10
 *
11
 * @property string $url
12
 */
13
trait HasUrl
14
{
15
    use Activatable;
16
17
    /**
18
     * @return string
19
     */
20
    public function url(): string
21
    {
22
        return $this->url;
23
    }
24
25
    /**
26
     * @param string $url
27
     *
28
     * @return $this
29
     */
30
    public function setUrl(string $url)
31
    {
32
        $this->url = $url;
33
34
        return $this;
35
    }
36
37
    /**
38
     * @param string $url
39
     * @param string $root
40
     *
41
     * @return $this
42
     */
43
    public function determineActiveForUrl(string $url, string $root = '/')
44
    {
45
        $itemUrl = Url::fromString($this->url);
46
        $matchUrl = Url::fromString($url);
47
48
        // If the hosts don't match, this url isn't active.
49
        if ($itemUrl->getHost() !== $matchUrl->getHost()) {
50
            return $this->setInactive();
51
        }
52
53
        // If this url doesn't start with the root, it's inactive.
54
        if (! Str::startsWith($itemUrl->getPath(), $root)) {
55
            return $this->setInactive();
56
        }
57
58
        // For the next comparisons we just need the paths, and we'll remove
59
        // the root first.
60
        $itemPath = Str::removeFromStart($root, $itemUrl->getPath());
61
        $matchPath = Str::removeFromStart($root, $matchUrl->getPath());
62
63
        // If this url starts with the url we're matching with, it's active.
64
        if (Str::startsWith($matchPath, $itemPath)) {
65
            return $this->setActive();
66
        }
67
68
        return $this->setInactive();
69
    }
70
}
71