| Conditions | 10 |
| Paths | 19 |
| Total Lines | 40 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 50 | public function match(array $server = [], array $post){ |
||
| 51 | $requestMethod = $server['REQUEST_METHOD']; |
||
| 52 | $requestUri = $server['REQUEST_URI']; |
||
| 53 | |||
| 54 | $restMethod = $this->getRestfullMethod($post); |
||
| 55 | |||
| 56 | if (null === $restMethod && !in_array($requestMethod, array_keys($this->routes))) { |
||
| 57 | return false; |
||
| 58 | } |
||
| 59 | |||
| 60 | $method = $restMethod ?: $requestMethod; |
||
| 61 | |||
| 62 | foreach ($this->routes[$method] as $resource) { |
||
| 63 | |||
| 64 | $args = []; |
||
| 65 | $route = key($resource); |
||
| 66 | $handler = reset($resource); |
||
| 67 | |||
| 68 | if(preg_match(self::REGVAL, $route)){ |
||
| 69 | list($args, ,$route) = $this->parseRegexRoute($requestUri, $route); |
||
| 70 | } |
||
| 71 | |||
| 72 | if(!preg_match("#^$route$#", $requestUri)){ |
||
| 73 | unset($this->routes[$method]); |
||
| 74 | continue ; |
||
| 75 | } |
||
| 76 | |||
| 77 | if(is_string($handler) && strpos($handler, '@')){ |
||
| 78 | list($ctrl, $method) = explode('@', $handler); |
||
| 79 | return ['controller' => $ctrl, 'method' => $method, 'args' => $args]; |
||
| 80 | } |
||
| 81 | |||
| 82 | if(empty($args)){ |
||
| 83 | return $handler(); |
||
| 84 | } |
||
| 85 | |||
| 86 | return call_user_func_array($handler, $args); |
||
| 87 | |||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 122 |