| Conditions | 10 |
| Paths | 1 |
| Total Lines | 54 |
| Lines | 30 |
| Ratio | 55.56 % |
| Tests | 30 |
| CRAP Score | 10 |
| 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 |
||
| 14 | 188 | public function transformEnums(): Closure |
|
| 15 | { |
||
| 16 | return function (array $transformations) { |
||
| 17 | 52 | if (isset($transformations['route'])) { |
|
| 18 | 8 | $route = $this->route(); |
|
|
|
|||
| 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'])) { |
| 36 | 20 | foreach ($transformations['query'] as $key => $enumClass) { |
|
| 37 | 20 | if (! $this->query->has($key)) { |
|
| 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'])) { |
| 52 | 24 | foreach ($transformations['request'] as $key => $enumClass) { |
|
| 53 | 24 | if (! $this->request->has($key)) { |
|
| 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 |
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.