biiiiiigmonster /
laravel-enum
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace BiiiiiigMonster\LaravelEnum\Rules; |
||||
| 4 | |||||
| 5 | use BiiiiiigMonster\LaravelEnum\EnumServiceProvider; |
||||
| 6 | use Closure; |
||||
| 7 | use Illuminate\Contracts\Validation\ValidationRule; |
||||
| 8 | |||||
| 9 | class Enum implements ValidationRule |
||||
| 10 | { |
||||
| 11 | public function __construct(protected string $enum) |
||||
| 12 | { |
||||
| 13 | } |
||||
| 14 | |||||
| 15 | public function passes(string $attribute, mixed $value): bool |
||||
|
0 ignored issues
–
show
|
|||||
| 16 | { |
||||
| 17 | if (! enum_exists($this->enum)) { |
||||
|
0 ignored issues
–
show
The function
enum_exists was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 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 |
||||
| 33 | { |
||||
| 34 | if (! $this->passes($attribute, $value)) { |
||||
| 35 | $fail(EnumServiceProvider::LANG_NAMESPACE.'::validations.enumerate')->translate(); |
||||
| 36 | } |
||||
| 37 | } |
||||
| 38 | } |
||||
| 39 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.