| Conditions | 19 |
| Paths | 325 |
| Total Lines | 59 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | 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 |
||
| 23 | public function __invoke(ContainerInterface $container, $resolvedName, array $options = null) |
||
|
|
|||
| 24 | { |
||
| 25 | if ($options === null) { |
||
| 26 | return new Generic(); |
||
| 27 | } |
||
| 28 | |||
| 29 | // Parameter normalization |
||
| 30 | if (!isset($options['path']) && isset($options[0])) { |
||
| 31 | $options['path'] = $options[0]; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (isset($options['defaults']) && isset($options[1])) { |
||
| 35 | $options['defaults'] += $options[1]; |
||
| 36 | } elseif (isset($options[1])) { |
||
| 37 | $options['defaults'] = $options[1]; |
||
| 38 | } |
||
| 39 | |||
| 40 | if (isset($options['methods']) && isset($options[2])) { |
||
| 41 | $options['methods'] = array_merge($options[2], $options['methods']); |
||
| 42 | } elseif (isset($options[2])) { |
||
| 43 | $options['methods'] = $options[2]; |
||
| 44 | } |
||
| 45 | |||
| 46 | // Try to retrive path and hostname parser |
||
| 47 | $parserManager = $container->get(ParserManager::class); |
||
| 48 | |||
| 49 | if (isset($options['path_parser'])) { |
||
| 50 | $pathParser = $parserManager->build($options['path_parser'], $options); |
||
| 51 | } elseif (isset($options['path'])) { |
||
| 52 | $pathParser = $parserManager->build('PathSegment', $options); |
||
| 53 | } else { |
||
| 54 | $pathParser = null; |
||
| 55 | } |
||
| 56 | |||
| 57 | if (isset($options['hostname_parser'])) { |
||
| 58 | $hostnameParser = $parserManager->build($options['hostname_parser'], $options); |
||
| 59 | } elseif (isset($options['hostname'])) { |
||
| 60 | $hostnameParser = $parserManager->build('HostnameSegment', $options); |
||
| 61 | } else { |
||
| 62 | $hostnameParser = null; |
||
| 63 | } |
||
| 64 | |||
| 65 | // Setup children if they exist |
||
| 66 | if (isset($options['children'])) { |
||
| 67 | $children = new LazyRouteCollection($container->get(RouteManager::class), $options['children']); |
||
| 68 | } else { |
||
| 69 | $children = null; |
||
| 70 | } |
||
| 71 | |||
| 72 | return new Generic( |
||
| 73 | $pathParser, |
||
| 74 | $hostnameParser, |
||
| 75 | isset($options['methods']) ? $options['methods'] : null, |
||
| 76 | isset($options['secure']) ? $options['secure'] : null, |
||
| 77 | isset($options['port']) ? $options['port'] : null, |
||
| 78 | isset($options['defaults']) ? $options['defaults'] : [], |
||
| 79 | $children |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | } |
||
| 83 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.