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.
Completed
Push — master ( b1b0e4...487ec3 )
by Tom
12:48 queued 11s
created

EnumServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 40.82 %

Coupling/Cohesion

Components 2
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 7
dl 20
loc 49
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
A register() 0 8 1
A bootValidationRules() 20 26 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Spatie\Enum\Laravel;
4
5
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
6
use Illuminate\Support\Facades\Validator;
7
use Illuminate\Support\ServiceProvider;
8
use Spatie\Enum\Laravel\Commands\MakeEnum;
9
use Spatie\Enum\Laravel\Rules\EnumIndexRule;
10 132
use Spatie\Enum\Laravel\Rules\EnumNameRule;
11
use Spatie\Enum\Laravel\Rules\EnumRule;
12 132
use Spatie\Enum\Laravel\Rules\EnumValueRule;
13
14 132
class EnumServiceProvider extends ServiceProvider
15 132
{
16
    public function boot()
17 132
    {
18
        $this->publishes([
19
            __DIR__.'/../resources/lang' => resource_path('lang/vendor/enum'),
20
        ]);
21
22
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'enum');
23
24
        $this->bootValidationRules();
25
    }
26
27
    public function register()
28
    {
29
        $this->app->bind('command.make:enum', MakeEnum::class);
30
31
        $this->commands([
32
            'command.make:enum',
33
        ]);
34
    }
35
36
    public function bootValidationRules(): void
37
    {
38 View Code Duplication
        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.

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

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
            $enum = $parameters[0] ?? null;
40
41
            return (new EnumRule($enum))->passes($attribute, $value);
42
        });
43
44 View Code Duplication
        Validator::extend('enum_index', 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.

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

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
            $enum = $parameters[0] ?? null;
46
47
            return (new EnumIndexRule($enum))->passes($attribute, $value);
48
        });
49
50 View Code Duplication
        Validator::extend('enum_name', 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.

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

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
            $enum = $parameters[0] ?? null;
52
53
            return (new EnumNameRule($enum))->passes($attribute, $value);
54
        });
55
56 View Code Duplication
        Validator::extend('enum_value', 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.

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

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
            $enum = $parameters[0] ?? null;
58
59
            return (new EnumValueRule($enum))->passes($attribute, $value);
60
        });
61
    }
62
}
63