Total Complexity | 7 |
Total Lines | 27 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class Enum implements ValidationRule |
||
10 | { |
||
11 | public function __construct(protected string $enum) |
||
13 | } |
||
14 | |||
15 | public function passes(string $attribute, mixed $value): bool |
||
|
|||
16 | { |
||
17 | if (! enum_exists($this->enum)) { |
||
18 | return false; |
||
19 | } |
||
20 | |||
21 | if ($value instanceof $this->enum) { |
||
22 | return true; |
||
23 | } |
||
24 | |||
25 | if (! method_exists($this->enum, 'tryFrom')) { |
||
26 | return false; |
||
27 | } |
||
28 | |||
29 | return ! is_null($this->enum::tryFrom($value)); |
||
30 | } |
||
31 | |||
32 | public function validate(string $attribute, mixed $value, Closure $fail): void |
||
36 | } |
||
37 | } |
||
39 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.