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
Pull Request — master (#13)
by Tom
06:11
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 25
cts 25
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\Support\ServiceProvider;
6
use Spatie\Enum\Laravel\Rules\EnumRule;
7
use Illuminate\Support\Facades\Validator;
8
use Spatie\Enum\Laravel\Commands\MakeEnum;
9
use Spatie\Enum\Laravel\Rules\EnumNameRule;
10
use Spatie\Enum\Laravel\Rules\EnumIndexRule;
11
use Spatie\Enum\Laravel\Rules\EnumValueRule;
12
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
13
14
class EnumServiceProvider extends ServiceProvider
15
{
16 256
    public function boot()
17
    {
18 256
        $this->publishes([
19 256
            __DIR__.'/../resources/lang' => resource_path('lang/vendor/enum'),
20
        ]);
21
22 256
        $this->loadTranslationsFrom(__DIR__.'/../resources/lang/', 'enum');
23
24 256
        $this->bootValidationRules();
25 256
    }
26
27 256
    public function register()
28
    {
29 256
        $this->app->bind('command.make:enum', MakeEnum::class);
30
31 256
        $this->commands([
32 256
            'command.make:enum',
33
        ]);
34 256
    }
35
36 256
    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 8
            $enum = $parameters[0] ?? null;
40
41 8
            return (new EnumRule($enum))->passes($attribute, $value);
42 256
        });
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 8
            $enum = $parameters[0] ?? null;
46
47 8
            return (new EnumIndexRule($enum))->passes($attribute, $value);
48 256
        });
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 8
            $enum = $parameters[0] ?? null;
52
53 8
            return (new EnumNameRule($enum))->passes($attribute, $value);
54 256
        });
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 8
            $enum = $parameters[0] ?? null;
58
59 8
            return (new EnumValueRule($enum))->passes($attribute, $value);
60 256
        });
61 256
    }
62
}
63