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
Pull Request — master (#13)
by Tom
08:31
created

Enum::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Spatie\Enum\Laravel\Rules;
4
5
use Exception;
6
use Spatie\Enum\Enumerable;
7
use InvalidArgumentException;
8
use Illuminate\Support\Facades\Lang;
9
use Illuminate\Contracts\Validation\Rule;
10
11
class Enum implements Rule
12
{
13
    protected $rule = 'enum';
14
15
    /** @var Enumerable */
16
    protected $enum;
17
18
    /** @var string */
19
    protected $attribute;
20
21
    /** @var mixed */
22
    protected $value;
23
24 48
    public function __construct(string $enum)
25
    {
26 48
        if (! isset(class_implements($enum)[Enumerable::class])) {
27
            throw new InvalidArgumentException("The given class {$enum} does not implement the Enumerable interface.");
28
        }
29
30 48
        $this->enum = $enum;
0 ignored issues
show
Documentation Bug introduced by
It seems like $enum of type string is incompatible with the declared type object<Spatie\Enum\Enumerable> of property $enum.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31 48
    }
32
33 12
    public function passes($attribute, $value): bool
34
    {
35 12
        $this->attribute = $attribute;
36 12
        $this->value = $value;
37
38
        try {
39 12
            $this->enum::make($value);
40
41 12
            return true;
42 12
        } catch (Exception $ex) {
43 12
            return false;
44
        }
45
    }
46
47
    public function message(): string
48
    {
49
        return Lang::trans('enum::validation.'.$this->rule, [
50
            'attribute' => $this->attribute,
51
            'value' => $this->value,
52
            'enum' => $this->enum,
53
        ]);
54
    }
55
}
56