| Conditions | 10 | 
| Paths | 14 | 
| Total Lines | 44 | 
| 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 | ||
| 35 | public function allows(string $url, ?string $userAgent = '*'): bool | ||
| 36 |     { | ||
| 37 | $userAgent = strtolower($userAgent); | ||
| 38 | |||
| 39 |         if ($userAgent === null) { | ||
| 40 | $userAgent = '*'; | ||
| 41 | } | ||
| 42 | |||
| 43 | $path = parse_url($url, PHP_URL_PATH) ?? ''; | ||
| 44 | |||
| 45 | $disallows = $this->disallowsPerUserAgent[$userAgent] ?? $this->disallowsPerUserAgent['*'] ?? []; | ||
| 46 | |||
| 47 | // check for exact | ||
| 48 | |||
| 49 | $type = null; | ||
| 50 |         if ($return = $this->pathIsDenied($path, $disallows, $type) !== null) { | ||
| 51 | |||
| 52 | // if it's in a dir, maybe wildcard authorize or forbid it | ||
| 53 |             if ($type === 1 && $wildCardReturn = $this->checkForWildcard($url, $userAgent) !== null) { | ||
| 54 | return ! $wildCardReturn; | ||
| 55 | } | ||
| 56 | |||
| 57 | // if it's in a dir but wildcard forbid access | ||
| 58 |             if ($type === 1 && $wildCardReturn = $this->pathIsDenied($path, $disallows) !== null) { | ||
| 59 |                 if ($wildCardReturn === true) { | ||
| 60 | return false; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | return ! $return; | ||
| 65 | } | ||
| 66 | |||
| 67 | // check for wildcrad user agent | ||
| 68 |         if ($return = $this->checkForWildcard($url, $userAgent) !== null) { | ||
| 69 | return ! $return; | ||
| 70 | } | ||
| 71 | |||
| 72 | // check for wildcard | ||
| 73 |         if ($return = $this->pathIsDenied($path, $disallows) !== null) { | ||
| 74 | return ! $return; | ||
| 75 | } | ||
| 76 | |||
| 77 | return true; | ||
| 78 | } | ||
| 79 | |||
| 186 |