Conditions | 10 |
Paths | 14 |
Total Lines | 46 |
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 | |||
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 | |||
70 | return ! $return; |
||
71 | } |
||
72 | |||
73 | // check for wildcard |
||
74 | if ($return = $this->pathIsDenied($path, $disallows) !== null) { |
||
75 | |||
76 | return ! $return; |
||
77 | } |
||
78 | |||
79 | return true; |
||
80 | } |
||
81 | |||
193 |