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
10:45
created

EnumRequest   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 78
Duplicated Lines 43.59 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 34
loc 78
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C transformEnums() 34 71 12

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
    const REQUEST_ROUTE = 'route';
15
    const REQUEST_QUERY = 'query';
16
    const REQUEST_REQUEST = 'request';
17
18
    public function transformEnums(): Closure
19
    {
20
        return function (array $transformations) {
21
            if (isset($transformations[EnumRequest::REQUEST_ROUTE])) {
22
                $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...
23
24
                foreach ($transformations[EnumRequest::REQUEST_ROUTE] as $key => $enumClass) {
25
                    if (! $route->hasParameter($key)) {
26
                        continue;
27
                    }
28
29
                    $route->setParameter(
30
                        $key,
31
                        forward_static_call(
32
                            $enumClass.'::make',
33
                            $route->parameter($key)
34
                        )
35
                    );
36
                }
37
38
                unset($transformations[EnumRequest::REQUEST_ROUTE]);
39
            }
40
41 View Code Duplication
            if (isset($transformations[EnumRequest::REQUEST_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...
42
                foreach ($transformations[EnumRequest::REQUEST_QUERY] as $key => $enumClass) {
43
                    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...
44
                        continue;
45
                    }
46
47
                    $this->query->set(
48
                        $key,
49
                        forward_static_call(
50
                            $enumClass.'::make',
51
                            $this->query->get($key)
52
                        )
53
                    );
54
                }
55
56
                unset($transformations[EnumRequest::REQUEST_QUERY]);
57
            }
58
59 View Code Duplication
            if (isset($transformations[EnumRequest::REQUEST_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...
60
                foreach ($transformations[EnumRequest::REQUEST_REQUEST] as $key => $enumClass) {
61
                    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...
62
                        continue;
63
                    }
64
65
                    $this->request->set(
66
                        $key,
67
                        forward_static_call(
68
                            $enumClass.'::make',
69
                            $this->request->get($key)
70
                        )
71
                    );
72
                }
73
74
                unset($transformations[EnumRequest::REQUEST_REQUEST]);
75
            }
76
77
            foreach ($transformations as $key => $enumClass) {
78
                if (! isset($this[$key])) {
79
                    continue;
80
                }
81
82
                $this[$key] = forward_static_call(
83
                    $enumClass.'::make',
84
                    $this[$key]
85
                );
86
            }
87
        };
88
    }
89
}
90