Conditions | 12 |
Paths | 1 |
Total Lines | 54 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
20 | public function transformEnums(): Closure |
||
21 | { |
||
22 | return function (array $transformations): void { |
||
23 | if (isset($transformations[EnumRequest::REQUEST_ROUTE])) { |
||
24 | $route = $this->route(); |
||
|
|||
25 | |||
26 | /** @var string|Enum $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 | $enumClass::make($route->parameter($key)) |
||
35 | ); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | if (isset($transformations[EnumRequest::REQUEST_QUERY])) { |
||
40 | /** @var string|Enum $enumClass */ |
||
41 | foreach ($transformations[EnumRequest::REQUEST_QUERY] as $key => $enumClass) { |
||
42 | if (! $this->query->has($key)) { |
||
43 | continue; |
||
44 | } |
||
45 | |||
46 | $this->query->set( |
||
47 | $key, |
||
48 | $enumClass::make($this->query->get($key)) |
||
49 | ); |
||
50 | } |
||
51 | } |
||
52 | |||
53 | if (isset($transformations[EnumRequest::REQUEST_REQUEST])) { |
||
54 | /** @var string|Enum $enumClass */ |
||
55 | foreach ($transformations[EnumRequest::REQUEST_REQUEST] as $key => $enumClass) { |
||
56 | if (! $this->request->has($key)) { |
||
57 | continue; |
||
58 | } |
||
59 | |||
60 | $this->request->set( |
||
61 | $key, |
||
62 | $enumClass::make($this->request->get($key)) |
||
63 | ); |
||
64 | } |
||
65 | } |
||
66 | |||
67 | /** @var string|Enum $enumClass */ |
||
68 | foreach (Arr::except($transformations, [EnumRequest::REQUEST_ROUTE, EnumRequest::REQUEST_QUERY, EnumRequest::REQUEST_REQUEST]) as $key => $enumClass) { |
||
69 | if (! isset($this[$key])) { |
||
70 | continue; |
||
71 | } |
||
72 | |||
73 | $this[$key] = $enumClass::make($this[$key]); |
||
74 | } |
||
78 |
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.