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