| Conditions | 13 |
| Paths | 12 |
| Total Lines | 37 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 81 | protected function findRouteUri(Request $request) |
||
| 82 | { |
||
| 83 | $method = $request->getMethod(); |
||
| 84 | $uri = $request->getPathInfo(); |
||
| 85 | $key = $method . $uri; |
||
| 86 | if (isset($this->routes[$key])) { |
||
| 87 | return $uri; |
||
| 88 | } |
||
| 89 | |||
| 90 | $route = $request->route(); |
||
| 91 | if ($route instanceof \Illuminate\Routing\Route) { // Laravel |
||
| 92 | $action = $route->getAction(); |
||
| 93 | if (is_string($action['uses'])) { // Uses |
||
| 94 | $key = $method . $action['uses']; |
||
| 95 | if (isset($this->routesByUses[$key])) { |
||
| 96 | $uri = $this->routesByUses[$key]; |
||
| 97 | } |
||
| 98 | } elseif ($action['uses'] instanceof Closure) { // Closure |
||
| 99 | $key = $method . spl_object_hash($action['uses']); |
||
| 100 | if (isset($this->routesByClosure[$key])) { |
||
| 101 | $uri = $this->routesByClosure[$key]; |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } elseif (is_array($route)) { // Lumen |
||
| 105 | if (isset($route[1]['uses'])) { |
||
| 106 | $key = $method . $route[1]['uses']; |
||
| 107 | if (isset($this->routesByUses[$key])) { |
||
| 108 | $uri = $this->routesByUses[$key]; |
||
| 109 | } |
||
| 110 | } elseif (isset($route[1][0]) && $route[1][0] instanceof Closure) { |
||
| 111 | $key = $method . spl_object_hash($route[1][0]); |
||
| 112 | if (isset($this->routesByClosure[$key])) { |
||
| 113 | $uri = $this->routesByClosure[$key]; |
||
| 114 | } |
||
| 115 | } |
||
| 116 | } |
||
| 117 | return $uri; |
||
| 118 | } |
||
| 119 | } |