| Conditions | 7 |
| Paths | 18 |
| Total Lines | 61 |
| Code Lines | 35 |
| 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 |
||
| 58 | public function display(): array |
||
| 59 | { |
||
| 60 | // Récupère nos paramètres |
||
| 61 | // Route sous forme de callback |
||
| 62 | if (is_callable($this->router->controllerName())) { |
||
| 63 | $method = new ReflectionFunction($this->router->controllerName()); |
||
| 64 | } else { |
||
| 65 | try { |
||
| 66 | $method = new ReflectionMethod($this->router->controllerName(), $this->router->methodName()); |
||
| 67 | } catch (ReflectionException $e) { |
||
| 68 | // Si nous sommes ici, la méthode n'existe pas |
||
| 69 | // et est probablement calculé dans _remap. |
||
| 70 | $method = new ReflectionMethod($this->router->controllerName(), '_remap'); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | $rawParams = $method->getParameters(); |
||
| 75 | |||
| 76 | $params = []; |
||
| 77 | |||
| 78 | foreach ($rawParams as $key => $param) { |
||
| 79 | $params[] = [ |
||
| 80 | 'name' => '$' . $param->getName() . ' = ', |
||
| 81 | 'value' => $this->router->params()[$key] ?? |
||
| 82 | ' <empty> | default: ' |
||
| 83 | . var_export( |
||
| 84 | $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null, |
||
| 85 | true |
||
| 86 | ), |
||
| 87 | ]; |
||
| 88 | } |
||
| 89 | |||
| 90 | $matchedRoute = [ |
||
| 91 | [ |
||
| 92 | 'directory' => $this->router->directory(), |
||
| 93 | 'controller' => $this->router->controllerName(), |
||
| 94 | 'method' => $this->router->methodName(), |
||
| 95 | 'paramCount' => count($this->router->params()), |
||
| 96 | 'truePCount' => count($params), |
||
| 97 | 'params' => $params ?? [], |
||
| 98 | ], |
||
| 99 | ]; |
||
| 100 | |||
| 101 | // Routes définies |
||
| 102 | $routes = []; |
||
| 103 | |||
| 104 | foreach ($this->definedRouteCollector->collect(false) as $route) { |
||
| 105 | // filtre pour les chaînes, car les rappels ne sont pas affichable |
||
| 106 | if ($route['handler'] !== '(Closure)') { |
||
| 107 | $routes[] = [ |
||
| 108 | 'method' => strtoupper($route['method']), |
||
| 109 | 'route' => $route['route'], |
||
| 110 | 'name' => $route['name'], |
||
| 111 | 'handler' => $route['handler'], |
||
| 112 | ]; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | return [ |
||
| 117 | 'matchedRoute' => $matchedRoute, |
||
| 118 | 'routes' => $routes, |
||
| 119 | ]; |
||
| 148 |