| Conditions | 12 |
| Paths | 28 |
| Total Lines | 46 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 84 | public function match(string $method, UriInterface $uri): ?Route |
||
| 85 | { |
||
| 86 | $requestPath = $uri->getPath(); |
||
| 87 | |||
| 88 | if ('/' !== $requestPath && isset(Route::URL_PREFIX_SLASHES[$requestPath[-1]])) { |
||
| 89 | $uri = $uri->withPath($requestPath = \substr($requestPath, 0, -1)); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (isset($this->staticRouteMap[$requestPath])) { |
||
| 93 | $staticRoute = $this->staticRouteMap[$requestPath]; |
||
| 94 | |||
| 95 | if (!isset($staticRoute[$method])) { |
||
| 96 | throw new MethodNotAllowedException(\array_keys($staticRoute), $uri->getPath(), $method); |
||
| 97 | } |
||
| 98 | |||
| 99 | if (!empty($hostsRegex = $staticRoute[$method][0])) { |
||
| 100 | $hostAndPost = $uri->getHost() . (null !== $uri->getPort() ? ':' . $uri->getPort() : ''); |
||
| 101 | |||
| 102 | if (!\preg_match($hostsRegex, $hostAndPost, $hostsVar)) { |
||
| 103 | if (isset($this->regexToRoutesMap)) { |
||
| 104 | goto retry_routing; |
||
| 105 | } |
||
| 106 | |||
| 107 | throw new UriHandlerException(\sprintf('Unfortunately current host "%s" is not allowed on requested static path [%s].', $uri->getHost(), $uri->getPath()), 400); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | $route = $this->routes[$routeId = $staticRoute[$method][1]]; |
||
| 112 | |||
| 113 | return $this->matchRoute($route, $uri, \array_merge($this->variableRouteData[$routeId], $hostsVar ?? [])); |
||
| 114 | } |
||
| 115 | |||
| 116 | retry_routing: |
||
| 117 | if (isset($this->regexToRoutesMap) && \preg_match($this->regexToRoutesMap, $method . \strpbrk((string) $uri, '/'), $matches)) { |
||
|
|
|||
| 118 | $route = $this->routes[$routeId = $matches['MARK']]; |
||
| 119 | |||
| 120 | if (!empty($matches[1])) { |
||
| 121 | throw new MethodNotAllowedException($route->get('methods'), $uri->getPath(), $method); |
||
| 122 | } |
||
| 123 | |||
| 124 | unset($matches[0], $matches[1], $matches['MARK']); |
||
| 125 | |||
| 126 | return $this->matchRoute($route, $uri, $this->variableRouteData[$routeId], $matches); |
||
| 127 | } |
||
| 128 | |||
| 129 | return null; |
||
| 130 | } |
||
| 185 |