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.

Host   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 7

4 Methods

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