| Conditions | 1 |
| Paths | 1 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 13 | public function getFunctions(): array |
||
| 14 | { |
||
| 15 | return [ |
||
| 16 | new ExpressionFunction( |
||
| 17 | 'remote_id', |
||
| 18 | function (string $args): string { |
||
| 19 | return sprintf('$__location_service->loadLocationByRemoteId(%s)', $args); |
||
| 20 | }, |
||
| 21 | function (array $variables, string $remoteId): Location { |
||
| 22 | return $variables['__location_service']->loadLocationByRemoteId($remoteId); |
||
| 23 | } |
||
| 24 | ), |
||
| 25 | new ExpressionFunction( |
||
| 26 | 'local_id', |
||
| 27 | function (string $args): string { |
||
| 28 | return sprintf('$__location_service->loadLocation(%s)', $args); |
||
| 29 | }, |
||
| 30 | function (array $variables, int $id): Location { |
||
| 31 | return $variables['__location_service']->loadLocation($id); |
||
| 32 | } |
||
| 33 | ), |
||
| 34 | new ExpressionFunction( |
||
| 35 | 'path', |
||
| 36 | function (string $args): string { |
||
| 37 | return sprintf('$__location_service->loadLocationByPathString(%s)', $args); |
||
| 38 | }, |
||
| 39 | function (array $variables, string $path): Location { |
||
| 40 | return $variables['__location_service']->loadLocationByPathString($path); |
||
| 41 | } |
||
| 42 | ), |
||
| 43 | new ExpressionFunction( |
||
| 44 | 'parent', |
||
| 45 | function (string $args): string { |
||
| 46 | return sprintf('$__location_service->loadParentLocation(%s)', $args); |
||
| 47 | }, |
||
| 48 | function (array $variables, Location $location): Location { |
||
| 49 | return $variables['__location_service']->loadParentLocation($location); |
||
| 50 | } |
||
| 51 | ), |
||
| 52 | new ExpressionFunction( |
||
| 53 | 'root', |
||
| 54 | function (string $args): string { |
||
|
|
|||
| 55 | return '$__self->resolve($___named_references->getReference("__root"))'; |
||
| 56 | }, |
||
| 57 | function (array $variables): Location { |
||
| 58 | return $variables['__self']->resolve($variables['__named_references']->getReference('__root')); |
||
| 59 | } |
||
| 60 | ), |
||
| 61 | new ExpressionFunction( |
||
| 62 | 'named', |
||
| 63 | function (string $args): string { |
||
| 64 | return sprintf('$__self->resolve($___named_references->getReference(%s))', $args); |
||
| 65 | }, |
||
| 66 | function (array $variables, string $name): Location { |
||
| 67 | return $variables['__self']->resolve($variables['__named_references']->getReference($name)); |
||
| 68 | } |
||
| 69 | ), |
||
| 70 | ]; |
||
| 71 | } |
||
| 72 | } |
||
| 73 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.