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 ( f38163...fac936 )
by Sebastian
02:38
created

HasUrl::segment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
3
namespace Spatie\Menu\Traits;
4
5
/**
6
 * Expects a `$url` and a `$prefixes` property on the class.
7
 *
8
 * @property string $url
9
 * @property array $prefixes
10
 */
11
trait HasUrl
12
{
13
    /**
14
     * @return string
15
     */
16
    public function getUrl(): string
17
    {
18
        if (empty($this->prefixes)) {
19
            return $this->url;
20
        }
21
22
        return implode('', $this->prefixes) . '/' . ltrim($this->url, '/');
23
    }
24
25
    /**
26
     * Return a segment of the link's URL. This function works for both absolute
27
     * and relative URL's. The index is a 1-index based number. Trailing and
28
     * double slashes are ignored.
29
     *
30
     * Example: (new Link('Open Source', 'https://spatie.be/opensource'))->segment(1)
31
     *      => 'opensource'
32
     *
33
     * @param int $index
34
     *
35
     * @return string|null
36
     */
37
    public function segment(int $index)
38
    {
39
        $path = parse_url($this->url)['path'] ?? '';
40
41
        $segments = array_values(
42
            array_filter(
43
                explode('/', $path),
44
                function ($value) {
45
                    return $value !== '';
46
                }
47
            )
48
        );
49
50
        return $segments[$index - 1] ?? null;
51
    }
52
53
    /**
54
     * @param string $prefix
55
     *
56
     * @return $this
57
     */
58
    public function prefix(string $prefix)
59
    {
60
        $this->prefixes[] = $prefix;
61
62
        return $this;
63
    }
64
}
65