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.

HostOrSubdomain::passes()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
nc 6
nop 2
dl 0
loc 19
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
namespace ProtoneMedia\LaravelMixins\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Facades\Http;
8
use Pdp\Rules;
9
10
class HostOrSubdomain implements Rule
11
{
12
    private array $hosts;
13
14
    private $publicSuffixList;
15
16
    /**
17
     * Create a new rule instance.
18
     *
19
     * @param array|string $host
20
     */
21
    public function __construct($host, Rules $publicSuffixList = null)
22
    {
23
        $this->hosts = Arr::wrap($host);
24
25
        $this->publicSuffixList = $publicSuffixList ?: Rules::fromString(
26
            Http::get('https://publicsuffix.org/list/public_suffix_list.dat')
27
        );
28
    }
29
30
    public static function make($host): self
31
    {
32
        return new static($host);
33
    }
34
35
    /**
36
     * Determine if the validation rule passes.
37
     *
38
     * @param  string  $attribute
39
     * @param  mixed  $value
40
     * @return bool
41
     */
42
    public function passes($attribute, $value)
43
    {
44
        if (!parse_url($value, PHP_URL_SCHEME)) {
45
            $value = "https://{$value}";
46
        }
47
48
        $host = parse_url($value, PHP_URL_HOST);
49
50
        if (!$host) {
51
            return false;
52
        }
53
54
        $resolvedDomain = $this->publicSuffixList->resolve($host);
55
56
        if ($host !== $resolvedDomain->domain()->toString()) {
57
            return false;
58
        }
59
60
        return in_array($resolvedDomain->registrableDomain()->toString(), $this->hosts);
61
    }
62
63
    /**
64
     * Get the validation error message.
65
     *
66
     * @return string
67
     */
68
    public function message()
69
    {
70
        return __('validation.host');
71
    }
72
}
73