Conditions | 10 |
Paths | 32 |
Total Lines | 75 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 0 | Features | 5 |
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 |
||
162 | public function router(SystemInterface &$core, &$result) |
||
163 | { |
||
164 | //elapsed('Start routing'); |
||
165 | // Flag for matching SamsonPHP asynchronous requests |
||
166 | $async = $this->isAsynchronousRequest(); |
||
167 | // Get HTTP request path |
||
168 | $path = $this->requestURI;//$_SERVER['REQUEST_URI']; |
||
169 | // Get HTTP request method |
||
170 | $method = $_SERVER['REQUEST_METHOD']; |
||
171 | // Prepend HTTP request type, true - asynchronous |
||
172 | $method = ($async ? GenericRouteGenerator::ASYNC_PREFIX : '').$method; |
||
173 | |||
174 | $result = false; |
||
175 | |||
176 | // Remove first slash if present, add method to path, remove GET params, remove trailing slash |
||
177 | $path = rtrim(ltrim(strtok($path, '?'), '/'), '/'); |
||
178 | |||
179 | /** @var mixed $routeMetadata Dispatching result route metadata */ |
||
180 | if (is_array($routeMetadata = call_user_func(Core::ROUTING_LOGIC_FUNCTION, $path, $method))) { |
||
181 | // Check found route |
||
182 | if (count($routeMetadata) === 3) { |
||
183 | // Get callback info |
||
184 | list($module, $method) = explode("#", $routeMetadata[2]); |
||
185 | // Get module |
||
186 | $module = $core->module($module); |
||
187 | // Create callback |
||
188 | $callback = array($module, $method); |
||
189 | |||
190 | // Trigger found route event |
||
191 | Event::fire(self::EVENT_ROUTE_FOUND, array(&$module, $callback)); |
||
192 | |||
193 | // Check if we have vaild callback |
||
194 | if (is_callable($callback)) { |
||
195 | // Get object from callback and set it as current active core module |
||
196 | $core->active($module); |
||
197 | // Routing result |
||
198 | $result = call_user_func_array( |
||
199 | $callback, |
||
200 | $this->parseParameters($callback, $routeMetadata[1]) |
||
201 | ); |
||
202 | |||
203 | // If this is cached method |
||
204 | if (stripos($method, self::CACHE_PREFIX) !== false) { |
||
205 | // perform caching |
||
206 | $core->cached(); |
||
207 | } |
||
208 | |||
209 | // If this route is asynchronous |
||
210 | if ($async) { |
||
211 | // Set async response |
||
212 | $core->async(true); |
||
213 | |||
214 | // If controller action has failed |
||
215 | if (!isset($result['status']) || !$result['status']) { |
||
216 | $result['message'] = "\n" . 'Event failed: ' . $routeMetadata[0]; |
||
217 | $result['status'] = 0; |
||
218 | } |
||
219 | |||
220 | // Encode event result as json object |
||
221 | echo json_encode($result, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP); |
||
222 | |||
223 | // Mark as successful |
||
224 | $result = true; |
||
225 | } |
||
226 | } |
||
227 | |||
228 | // If no result is passed - consider success |
||
229 | $result = $result !== false ? true : $result; |
||
230 | } |
||
231 | } |
||
232 | |||
233 | //elapsed('Finished routing'); |
||
234 | // Return true or false depending on $result |
||
235 | return $result; |
||
236 | } |
||
237 | } |
||
238 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.