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 ( 53177f...cf3086 )
by Sebastian
02:24
created

Link::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Spatie\Menu;
4
5
use Spatie\HtmlElement\HtmlElement;
6
use Spatie\Menu\Traits\Activatable;
7
use Spatie\Menu\Traits\HtmlAttributes;
8
use Spatie\Menu\Traits\ParentAttributes;
9
10
class Link implements Item
11
{
12
    use Activatable, HtmlAttributes, ParentAttributes;
13
14
    /** @var string */
15
    protected $text;
16
17
    /** @var string */
18
    protected $url;
19
20
    /**
21
     * @param string $url
22
     * @param string $text
23
     */
24
    protected function __construct(string $url, string $text)
25
    {
26
        $this->url = $url;
27
        $this->text = $text;
28
        $this->active = false;
29
30
        $this->bootHtmlAttributes();
31
        $this->bootParentAttributes();
32
    }
33
34
    /**
35
     * @param string $url
36
     * @param string $text
37
     *
38
     * @return static
39
     */
40
    public static function to(string $url, string $text)
41
    {
42
        return new static($url, $text);
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getText() : string
49
    {
50
        return $this->text;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getUrl() : string
57
    {
58
        return $this->url;
59
    }
60
61
    /**
62
     * Return a segment of the link's URL. This function works for both absolute and relative URL's.
63
     * The index is a 1-index based number. Trailing and double slashes are ignored.
64
     *
65
     * Example: (new Link('Open Source', 'https://spatie.be/opensource'))->segment(1) => 'opensource'
66
     *
67
     * @param int $index
68
     *
69
     * @return string|null
70
     */
71
    public function segment(int $index)
72
    {
73
        $path = parse_url($this->url)['path'] ?? '';
74
75
        $segments = array_values(
76
            array_filter(
77
                explode('/', $path),
78
                function ($value) {
79
                    return $value !== '';
80
                }
81
            )
82
        );
83
84
        return $segments[$index - 1] ?? null;
85
    }
86
87
    /**
88
     * @param string $prefix
89
     *
90
     * @return $this
91
     */
92
    public function prefix(string $prefix)
93
    {
94
        $this->url = $prefix.'/'.ltrim($this->url, '/');
95
96
        return $this;
97
    }
98
99
    /**
100
     * @return string
101
     */
102
    public function render() : string
103
    {
104
        return HtmlElement::render(
105
            "a[href={$this->url}]",
106
            $this->htmlAttributes->toArray(),
107
            $this->text
108
        );
109
    }
110
}
111