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 (#7)
by Tom
06:43
created

EnumRequest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 52.63 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 30
loc 57
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B transformEnums() 30 54 10

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\Http;
4
5
use Closure;
6
7
/**
8
 * @internal This class is only used to get mixed into \Illuminate\Http\Request
9
 *
10
 * @mixin \Illuminate\Http\Request
11
 */
12
final class EnumRequest
13
{
14 188
    public function transformEnums(): Closure
15
    {
16
        return function (array $transformations) {
17 52
            if (isset($transformations['route'])) {
18 8
                $route = $this->route();
0 ignored issues
show
Bug introduced by
The method route() does not seem to exist on object<Spatie\Enum\Laravel\Http\EnumRequest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
20 8
                foreach ($transformations['route'] as $key => $enumClass) {
21 8
                    if (! $route->hasParameter($key)) {
22 4
                        continue;
23
                    }
24
25 4
                    $route->setParameter(
26 4
                        $key,
27 4
                        forward_static_call(
28 4
                            $enumClass.'::make',
29 4
                            $route->parameter($key)
30
                        )
31
                    );
32
                }
33
            }
34
35 52 View Code Duplication
            if (isset($transformations['query'])) {
0 ignored issues
show
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...
36 20
                foreach ($transformations['query'] as $key => $enumClass) {
37 20
                    if (! $this->query->has($key)) {
0 ignored issues
show
Bug introduced by
The property query does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
38 8
                        continue;
39
                    }
40
41 12
                    $this->query->set(
42 12
                        $key,
43 12
                        forward_static_call(
44 12
                            $enumClass.'::make',
45 12
                            $this->query->get($key)
46
                        )
47
                    );
48
                }
49
            }
50
51 52 View Code Duplication
            if (isset($transformations['request'])) {
0 ignored issues
show
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...
52 24
                foreach ($transformations['request'] as $key => $enumClass) {
53 24
                    if (! $this->request->has($key)) {
0 ignored issues
show
Bug introduced by
The property request does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
54 12
                        continue;
55
                    }
56
57 12
                    $this->request->set(
58 12
                        $key,
59 12
                        forward_static_call(
60 12
                            $enumClass.'::make',
61 12
                            $this->request->get($key)
62
                        )
63
                    );
64
                }
65
            }
66 188
        };
67
    }
68
}
69