| Conditions | 11 |
| Paths | 97 |
| Total Lines | 58 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 92 | public function handle() |
||
| 93 | { |
||
| 94 | try { |
||
| 95 | |||
| 96 | $query = $this->di->request->getRoute(); |
||
| 97 | $parts = $this->di->request->getRouteParts(); |
||
| 98 | |||
| 99 | // Match predefined routes |
||
| 100 | foreach ($this->routes as $route) { |
||
| 101 | if ($route->match($query)) { |
||
| 102 | return $route->handle(); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | // Default handling route as :controller/:action/:params using the dispatcher |
||
| 107 | $dispatcher = $this->di->dispatcher; |
||
| 108 | $dispatcher->setControllerName(isset($parts[0]) ? $parts[0] : 'index'); |
||
| 109 | |||
| 110 | if ($dispatcher->isValidController()) { |
||
| 111 | |||
| 112 | $dispatcher->setActionName(isset($parts[1]) ? $parts[1] : 'index'); |
||
| 113 | |||
| 114 | $params = []; |
||
| 115 | if (isset($parts[2])) { |
||
| 116 | $params = $parts; |
||
| 117 | array_shift($params); |
||
| 118 | array_shift($params); |
||
| 119 | } |
||
| 120 | $dispatcher->setParams($params); |
||
| 121 | |||
| 122 | if ($dispatcher->isCallable()) { |
||
| 123 | return $dispatcher->dispatch(); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | // Use the "catch-all" route |
||
| 128 | if ($this->defaultRoute) { |
||
| 129 | return $this->defaultRoute->handle(); |
||
| 130 | } |
||
| 131 | |||
| 132 | // No route was matched |
||
| 133 | $this->handleInternal('404'); |
||
| 134 | |||
| 135 | } catch (\Exception $e) { |
||
| 136 | |||
| 137 | // Exception codes can match a route for a http status code |
||
| 138 | $code = $e->getCode(); |
||
| 139 | $statusCodes = [403, 404, 500]; |
||
| 140 | if (in_array($code, $statusCodes)) { |
||
| 141 | |||
| 142 | $this->di->flash->setMessage($e->getMessage()); |
||
| 143 | $this->handleInternal($code); |
||
| 144 | |||
| 145 | } else { |
||
| 146 | throw $e; |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | } |
||
| 151 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.