| Conditions | 19 |
| Paths | 115 |
| Total Lines | 65 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 110 | public function match(ServerRequestInterface $request, $pathOffset) |
||
| 111 | { |
||
| 112 | $uri = $request->getUri(); |
||
| 113 | $params = $this->defaults; |
||
| 114 | |||
| 115 | // Verify scheme first, if set. |
||
| 116 | if (true === $this->secure && 'https' !== $uri->getScheme()) { |
||
| 117 | return MatchResult::fromSchemeFailure($uri->withScheme('https')); |
||
| 118 | } elseif (false === $this->secure && 'http' !== $uri->getScheme()) { |
||
| 119 | return MatchResult::fromSchemeFailure($uri->withScheme('http')); |
||
| 120 | } |
||
| 121 | |||
| 122 | // Then match hostname, if parser is set. |
||
| 123 | if (null !== $this->hostnameParser) { |
||
| 124 | $hostnameResult = $this->hostnameParser->parse($uri->getHost(), 0); |
||
| 125 | |||
| 126 | if (null === $hostnameResult || strlen($uri->getHost()) !== $hostnameResult->getMatchLength()) { |
||
| 127 | return null; |
||
| 128 | } |
||
| 129 | |||
| 130 | $params = $hostnameResult->getParams() + $params; |
||
| 131 | } |
||
| 132 | |||
| 133 | // Then match port, if set. |
||
| 134 | if (null !== $this->port) { |
||
| 135 | $port = $uri->getPort() ?: ('http' === $uri->getScheme() ? 80 : 443); |
||
| 136 | |||
| 137 | if ($port !== $this->port) { |
||
| 138 | return null; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | // Next match the path. |
||
| 143 | $completePathMatched = false; |
||
| 144 | |||
| 145 | if (null !== $this->pathParser) { |
||
| 146 | if (null === ($pathResult = $this->pathParser->parse($uri->getPath(), $pathOffset))) { |
||
| 147 | return null; |
||
| 148 | } |
||
| 149 | |||
| 150 | $pathOffset += $pathResult->getMatchLength(); |
||
| 151 | $completePathMatched = ($pathOffset === strlen($uri->getPath())); |
||
| 152 | $params = $pathResult->getParams() + $params; |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($completePathMatched) { |
||
| 156 | if (null === $this->methods || in_array($request->getMethod(), $this->methods)) { |
||
| 157 | return MatchResult::fromSuccess($params); |
||
| 158 | } |
||
| 159 | |||
| 160 | if (empty($this->methods)) { |
||
| 161 | // Special case: when no methods are defined at all, this route may simply not terminate. |
||
| 162 | return null; |
||
| 163 | } |
||
| 164 | |||
| 165 | return MatchResult::fromMethodFailure($this->methods); |
||
| 166 | } |
||
| 167 | |||
| 168 | // The path was not completely matched yet, so we check the children. |
||
| 169 | if (null === $this->children) { |
||
| 170 | return null; |
||
| 171 | } |
||
| 172 | |||
| 173 | return RouteCollectionMatcher::matchRouteCollection($this->children, $request, $pathOffset, $params); |
||
| 174 | } |
||
| 175 | |||
| 216 |