| Conditions | 13 |
| Paths | 19 |
| Total Lines | 46 |
| Code Lines | 26 |
| 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 |
||
| 71 | public function match(string $method, UriInterface $uri, callable $routes) |
||
| 72 | { |
||
| 73 | [$staticRoutes, $regexList, $variables] = $this->compiledData; |
||
| 74 | $requestPath = $uri->getPath(); |
||
| 75 | $matches = []; |
||
| 76 | |||
| 77 | if (empty($matchedIds = $staticRoutes[$requestPath] ?? [])) { |
||
| 78 | if (null === $regexList || !\preg_match($regexList, $requestPath, $matches, \PREG_UNMATCHED_AS_NULL)) { |
||
| 79 | if (isset($staticRoutes['*'][$requestPath])) { |
||
| 80 | $matchedIds = $staticRoutes['*'][$requestPath]; |
||
| 81 | goto found_a_route_match; |
||
| 82 | } |
||
| 83 | |||
| 84 | return null; |
||
| 85 | } |
||
| 86 | |||
| 87 | $matchedIds = [(int) $matches['MARK']]; |
||
| 88 | } |
||
| 89 | |||
| 90 | found_a_route_match: |
||
| 91 | foreach ($matchedIds as $matchedId) { |
||
| 92 | foreach ($variables[$method][$matchedId] ?? [] as $domain => $routeVar) { |
||
| 93 | [$matchedRoute, $hostsVar] = $routes($matchedId, $domain ?: null, $uri); |
||
| 94 | $requiredSchemes = $matchedRoute->getSchemes(); |
||
| 95 | |||
| 96 | if (null === $hostsVar) { |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | |||
| 100 | if ($requiredSchemes && !\in_array($uri->getScheme(), $requiredSchemes)) { |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (!empty($routeVar)) { |
||
| 105 | $matchInt = 0; |
||
| 106 | |||
| 107 | foreach ($routeVar as $key => $value) { |
||
| 108 | $matchedRoute->argument($key, $matches[++$matchInt] ?? $matches[$key] ?? $hostsVar[$key] ?? $value); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | return $matchedRoute; |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | return $matchedIds; |
||
| 117 | } |
||
| 119 |