biiiiiigmonster /
laravel-enum
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace BiiiiiigMonster\LaravelEnum\Rules; |
||||
| 4 | |||||
| 5 | use BiiiiiigMonster\LaravelEnum\Concerns\EnumTraits; |
||||
|
0 ignored issues
–
show
|
|||||
| 6 | use BiiiiiigMonster\LaravelEnum\Concerns\Meta; |
||||
| 7 | use BiiiiiigMonster\LaravelEnum\EnumServiceProvider; |
||||
| 8 | use Closure; |
||||
| 9 | use Illuminate\Contracts\Validation\ValidationRule; |
||||
| 10 | |||||
| 11 | class EnumMeta implements ValidationRule |
||||
| 12 | { |
||||
| 13 | public function __construct(protected string $enum, protected ?string $meta = null) |
||||
| 14 | { |
||||
| 15 | } |
||||
| 16 | |||||
| 17 | public function passes(string $attribute, mixed $value): bool |
||||
| 18 | { |
||||
| 19 | 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...
|
|||||
| 20 | return false; |
||||
| 21 | } |
||||
| 22 | |||||
| 23 | if ($value instanceof $this->enum) { |
||||
| 24 | return true; |
||||
| 25 | } |
||||
| 26 | |||||
| 27 | if (! in_array(EnumTraits::class, trait_uses_recursive($this->enum))) { |
||||
| 28 | return false; |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | if ($this->meta) { |
||||
| 32 | if (! is_subclass_of($this->meta, Meta::class)) { |
||||
| 33 | return false; |
||||
| 34 | } |
||||
| 35 | |||||
| 36 | $value = new $this->meta($value); |
||||
| 37 | } |
||||
| 38 | |||||
| 39 | return ! is_null($this->enum::tryFromMeta($value, $attribute)); |
||||
| 40 | } |
||||
| 41 | |||||
| 42 | public function validate(string $attribute, mixed $value, Closure $fail): void |
||||
| 43 | { |
||||
| 44 | if (! $this->passes($attribute, $value)) { |
||||
| 45 | $fail(EnumServiceProvider::LANG_NAMESPACE.'::validations.enum_meta')->translate(); |
||||
| 46 | } |
||||
| 47 | } |
||||
| 48 | } |
||||
| 49 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths