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.
Passed
Push — master ( 5c474a...09f246 )
by Pascal
12:33 queued 11s
created

HostOrSubdomain   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 61
rs 10
c 1
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A passes() 0 19 4
A message() 0 3 1
A __construct() 0 6 2
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