| Conditions | 10 |
| Paths | 8 |
| Total Lines | 23 |
| Code Lines | 14 |
| 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 |
||
| 62 | public static function getRelativeBaseUrl($scriptName, $phpSelf, $filename, $origScriptName) : string |
||
| 63 | { |
||
| 64 | if ($scriptName !== null && basename($scriptName) === $filename) { |
||
| 65 | return $scriptName; |
||
| 66 | } |
||
| 67 | if ($phpSelf !== null && basename($phpSelf) === $filename) { |
||
| 68 | return $phpSelf; |
||
| 69 | } |
||
| 70 | if ($origScriptName !== null && basename($origScriptName) === $filename) { |
||
| 71 | // 1and1 shared hosting compatibility. |
||
| 72 | return $origScriptName; |
||
| 73 | } |
||
| 74 | // Backtrack up the SCRIPT_FILENAME to find the portion |
||
| 75 | // matching PHP_SELF. |
||
| 76 | $baseUrl = '/'; |
||
| 77 | $basename = basename($filename); |
||
| 78 | if ($basename) { |
||
| 79 | $path = ($phpSelf ? trim($phpSelf, '/') : ''); |
||
| 80 | $basePos = strpos($path, $basename) ?: 0; |
||
| 81 | $baseUrl .= substr($path, 0, $basePos) . $basename; |
||
| 82 | } |
||
| 83 | return $baseUrl; |
||
| 84 | } |
||
| 85 | } |
||
| 86 |