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.

EnumServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 5
eloc 15
c 5
b 0
f 2
dl 0
loc 37
rs 10
ccs 3
cts 3
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A bootValidationRules() 0 6 1
A registerRequestTransformMacro() 0 3 1
A register() 0 9 1
A boot() 0 11 2
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
Unused Code introduced by
The parameter $validator is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
        Validator::extend('enum', function (string $attribute, $value, array $parameters, /** @scrutinizer ignore-unused */ ValidatorContract $validator): bool {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
            $enum = $parameters[0] ?? null;
48
49
            return (new EnumRule($enum))->passes($attribute, $value);
0 ignored issues
show
Bug introduced by
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 ignore-type  annotation

49
            return (new EnumRule(/** @scrutinizer ignore-type */ $enum))->passes($attribute, $value);
Loading history...
50
        });
51
    }
52
}
53