| Conditions | 10 |
| Paths | 14 |
| Total Lines | 43 |
| 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 | $type = null; |
||
| 49 | if ($return = $this->pathIsDenied($path, $disallows, $type) !== null) { |
||
| 50 | |||
| 51 | // if it's in a dir, maybe wildcard authorize or forbid it |
||
| 52 | if ($type === 1 && $wildCardReturn = $this->checkForWildcard($url, $userAgent) !== null) { |
||
| 53 | return $wildCardReturn; |
||
| 54 | } |
||
| 55 | |||
| 56 | // if it's in a dir but wildcard forbid access |
||
| 57 | if ($type === 1 && $wildCardReturn = $this->pathIsDenied($path, $disallows) !== null) { |
||
| 58 | if ($wildCardReturn === true) { |
||
| 59 | return false; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | return ! $return; |
||
| 64 | } |
||
| 65 | |||
| 66 | // check for wildcrad user agent |
||
| 67 | if ($return = $this->checkForWildcard($url, $userAgent) !== null) { |
||
| 68 | return ! $return; |
||
| 69 | } |
||
| 70 | |||
| 71 | // check for wildcard |
||
| 72 | if ($return = $this->pathIsDenied($path, $disallows) !== null) { |
||
| 73 | return ! $return; |
||
| 74 | } |
||
| 75 | |||
| 76 | return true; |
||
| 77 | } |
||
| 78 | |||
| 184 |