| Conditions | 12 |
| Paths | 1 |
| Total Lines | 69 |
| Lines | 32 |
| Ratio | 46.38 % |
| Changes | 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|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])) { |
|
| 43 | /** @var string|Enumerable $enumClass */ |
||
| 44 | foreach ($transformations[EnumRequest::REQUEST_QUERY] as $key => $enumClass) { |
||
| 45 | if (! $this->query->has($key)) { |
||
| 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])) { |
|
| 60 | /** @var string|Enumerable $enumClass */ |
||
| 61 | foreach ($transformations[EnumRequest::REQUEST_REQUEST] as $key => $enumClass) { |
||
| 62 | if (! $this->request->has($key)) { |
||
| 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 |
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.