1 | <?php |
||||
2 | |||||
3 | namespace Spatie\Enum\Laravel; |
||||
4 | |||||
5 | use Illuminate\Contracts\Validation\Validator as ValidatorContract; |
||||
6 | use Illuminate\Http\Request; |
||||
7 | use Illuminate\Support\Facades\Validator; |
||||
8 | use Illuminate\Support\ServiceProvider; |
||||
9 | use Spatie\Enum\Laravel\Commands\MakeEnum; |
||||
10 | 132 | use Spatie\Enum\Laravel\Http\EnumRequest; |
|||
11 | use Spatie\Enum\Laravel\Rules\EnumRule; |
||||
12 | 132 | ||||
13 | class EnumServiceProvider extends ServiceProvider |
||||
14 | 132 | { |
|||
15 | 132 | public function boot(): void |
|||
16 | { |
||||
17 | 132 | if ($this->app->runningInConsole()) { |
|||
18 | $this->publishes([ |
||||
19 | __DIR__.'/../resources/lang' => resource_path('lang/vendor/enum'), |
||||
20 | ], 'translation'); |
||||
21 | } |
||||
22 | |||||
23 | $this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'enum'); |
||||
24 | |||||
25 | $this->bootValidationRules(); |
||||
26 | } |
||||
27 | |||||
28 | public function register(): void |
||||
29 | { |
||||
30 | $this->app->bind('command.make:enum', MakeEnum::class); |
||||
31 | |||||
32 | $this->commands([ |
||||
33 | 'command.make:enum', |
||||
34 | ]); |
||||
35 | |||||
36 | $this->registerRequestTransformMacro(); |
||||
37 | } |
||||
38 | |||||
39 | protected function registerRequestTransformMacro(): void |
||||
40 | { |
||||
41 | Request::mixin(new EnumRequest); |
||||
42 | } |
||||
43 | |||||
44 | public function bootValidationRules(): void |
||||
45 | { |
||||
46 | Validator::extend('enum', function (string $attribute, $value, array $parameters, ValidatorContract $validator): bool { |
||||
0 ignored issues
–
show
|
|||||
47 | $enum = $parameters[0] ?? null; |
||||
48 | |||||
49 | return (new EnumRule($enum))->passes($attribute, $value); |
||||
0 ignored issues
–
show
It seems like
$enum can also be of type null ; however, parameter $enum of Spatie\Enum\Laravel\Rules\EnumRule::__construct() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
50 | }); |
||||
51 | } |
||||
52 | } |
||||
53 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.