| Conditions | 10 |
| Paths | 74 |
| Total Lines | 36 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 101 | private function doMerge(string $prefix, self $routes, bool $merge = true): void |
||
| 102 | { |
||
| 103 | $unnamedRoutes = []; |
||
| 104 | |||
| 105 | foreach ($this->offsetGet('group') as $namePrefix => $group) { |
||
| 106 | $prefix .= \is_string($namePrefix) ? $namePrefix : ''; |
||
| 107 | |||
| 108 | foreach ($group['routes'] ?? [] as $route) { |
||
| 109 | if (null === $name = $route->get('name')) { |
||
| 110 | $name = $route->generateRouteName(''); |
||
| 111 | |||
| 112 | if (isset($unnamedRoutes[$name])) { |
||
| 113 | $name .= ('_' !== $name[-1] ? '_' : '') . ++$unnamedRoutes[$name]; |
||
| 114 | } else { |
||
| 115 | $unnamedRoutes[$name] = 0; |
||
| 116 | } |
||
| 117 | } |
||
| 118 | |||
| 119 | $routes['routes'][] = $route->bind($prefix . $name); |
||
| 120 | |||
| 121 | if (null !== $routes->profiler) { |
||
| 122 | $routes->profiler->addProfile($route); |
||
| 123 | } |
||
| 124 | |||
| 125 | $this->processRouteMaps($route, $routes->countRoutes, $routes); |
||
| 126 | |||
| 127 | ++$routes->countRoutes; |
||
| 128 | } |
||
| 129 | |||
| 130 | if ($group->offsetExists('group')) { |
||
| 131 | $group->doMerge($prefix, $routes, false); |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | if ($merge) { |
||
| 136 | $routes->offsetUnset('group'); // Unset grouping ... |
||
| 137 | } |
||
| 170 |