| Conditions | 10 |
| Paths | 51 |
| Total Lines | 54 |
| Code Lines | 29 |
| 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 |
||
| 131 | private function matchRoutes(Request $request, Response $response) |
||
| 132 | { |
||
| 133 | $stack = []; |
||
| 134 | $badMethod = false; |
||
| 135 | |||
| 136 | foreach ($this->routes as $route) { |
||
| 137 | if (!$route->isParsed()) { |
||
| 138 | $route->parse(); |
||
| 139 | } |
||
| 140 | |||
| 141 | if (preg_match('#'.$route->parsedRoute.'$#', $request->httpRequest->getPath(), $array)) { |
||
| 142 | if ($route->method != strtoupper($request->httpRequest->getMethod())) { |
||
| 143 | $badMethod = true; |
||
| 144 | continue; |
||
| 145 | } |
||
| 146 | |||
| 147 | $methodArgs = []; |
||
| 148 | |||
| 149 | foreach ($array as $name => $value) { |
||
| 150 | if (!is_int($name)) { |
||
| 151 | $methodArgs[$name] = $value; |
||
| 152 | } |
||
| 153 | } |
||
| 154 | |||
| 155 | if (count($methodArgs) > 0) { |
||
| 156 | $request->setData($methodArgs); |
||
| 157 | } |
||
| 158 | |||
| 159 | $route->on('error', function () { |
||
| 160 | $this->emit('error', func_get_args()); |
||
| 161 | }); |
||
| 162 | |||
| 163 | $stack[] = function ($next) use ($route, $request, $response) { |
||
| 164 | $route->run($request, $response, $next); |
||
| 165 | }; |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | if (count($stack)) { |
||
| 170 | $stack[] = function () use ($response) { |
||
| 171 | $response->end(); |
||
| 172 | }; |
||
| 173 | |||
| 174 | $this->waterfall($stack); |
||
| 175 | return; |
||
| 176 | } |
||
| 177 | |||
| 178 | if ($badMethod) { |
||
| 179 | $this->emit('MethodNotAllowed', array(&$request, &$response, $next)); |
||
| 180 | return; |
||
| 181 | } |
||
| 182 | |||
| 183 | $this->emit('NotFound', array($request, $response, $next)); |
||
| 184 | } |
||
| 185 | } |
||
| 186 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.