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 ( 7b7e11...0b8297 )
by Tom
13:15 queued 11s
created

EnumRequest::transformEnums()   C

Complexity

Conditions 12
Paths 1

Size

Total Lines 69

Duplication

Lines 32
Ratio 46.38 %

Importance

Changes 0
Metric Value
dl 32
loc 69
rs 6.2496
c 0
b 0
f 0
cc 12
nc 1
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Spatie\Enum\Laravel\Http;
4
5
use Closure;
6
use Illuminate\Support\Arr;
7
use Spatie\Enum\Enumerable;
8
9
/**
10
 * @internal This class is only used to get mixed into \Illuminate\Http\Request
11
 *
12
 * @mixin \Illuminate\Http\Request
13
 */
14
final class EnumRequest
15
{
16
    const REQUEST_ROUTE = 'route';
17
    const REQUEST_QUERY = 'query';
18
    const REQUEST_REQUEST = 'request';
19
20
    public function transformEnums(): Closure
21
    {
22
        return function (array $transformations): void {
23
            if (isset($transformations[EnumRequest::REQUEST_ROUTE])) {
24
                $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...
25
26
                /** @var string|Enumerable $enumClass */
27
                foreach ($transformations[EnumRequest::REQUEST_ROUTE] as $key => $enumClass) {
28
                    if (! $route->hasParameter($key)) {
29
                        continue;
30
                    }
31
32
                    $route->setParameter(
33
                        $key,
34
                        forward_static_call(
35
                            [$enumClass, 'make'],
36
                            $route->parameter($key)
37
                        )
38
                    );
39
                }
40
            }
41
42 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...
43
                /** @var string|Enumerable $enumClass */
44
                foreach ($transformations[EnumRequest::REQUEST_QUERY] as $key => $enumClass) {
45
                    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...
46
                        continue;
47
                    }
48
49
                    $this->query->set(
50
                        $key,
51
                        forward_static_call(
52
                            [$enumClass, 'make'],
53
                            $this->query->get($key)
54
                        )
55
                    );
56
                }
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
                /** @var string|Enumerable $enumClass */
61
                foreach ($transformations[EnumRequest::REQUEST_REQUEST] as $key => $enumClass) {
62
                    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...
63
                        continue;
64
                    }
65
66
                    $this->request->set(
67
                        $key,
68
                        forward_static_call(
69
                            [$enumClass, 'make'],
70
                            $this->request->get($key)
71
                        )
72
                    );
73
                }
74
            }
75
76
            /** @var string|Enumerable $enumClass */
77
            foreach (Arr::except($transformations, [EnumRequest::REQUEST_ROUTE, EnumRequest::REQUEST_QUERY, EnumRequest::REQUEST_REQUEST]) 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