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 ( fef613...8eeb44 )
by Pascal
01:36 queued 12s
created

Host::__construct()   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 1
1
<?php
2
3
namespace ProtoneMedia\LaravelMixins\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Str;
8
9
class Host implements Rule
10
{
11
    private array $hosts;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
12
13
    /**
14
     * Create a new rule instance.
15
     *
16
     * @param array|string $host
17
     */
18
    public function __construct($host)
19
    {
20
        $this->hosts = Arr::wrap($host);
21
    }
22
23
    public static function make($host): self
24
    {
25
        return new static($host);
26
    }
27
28
    /**
29
     * Determine if the validation rule passes.
30
     *
31
     * @param  string  $attribute
32
     * @param  mixed  $value
33
     * @return bool
34
     */
35
    public function passes($attribute, $value)
36
    {
37
        if (!parse_url($value, PHP_URL_SCHEME)) {
38
            $value = "https://{$value}";
39
        }
40
41
        $host = parse_url($value, PHP_URL_HOST);
42
43
        if (!$host) {
44
            return false;
45
        }
46
47
        if (Str::startsWith($host, 'www.')) {
48
            $host = Str::after($host, 'www.');
49
        }
50
51
        return in_array($host, $this->hosts);
52
    }
53
54
    /**
55
     * Get the validation error message.
56
     *
57
     * @return string
58
     */
59
    public function message()
60
    {
61
        return __('validation.host');
62
    }
63
}
64