| Conditions | 19 |
| Paths | 83 |
| Total Lines | 46 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 11 | public static function get($key, $default = null) |
||
| 12 | { |
||
| 13 | if ($key === 'HTTPS') { |
||
| 14 | if (isset($_SERVER['HTTPS'])) { |
||
| 15 | return !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; |
||
| 16 | } |
||
| 17 | |||
| 18 | return strpos((string)env('SCRIPT_URI'), 'https://') === 0; |
||
| 19 | } |
||
| 20 | |||
| 21 | if ($key === 'SCRIPT_NAME' && env('CGI_MODE') && isset($_ENV['SCRIPT_URL'])) { |
||
| 22 | $key = 'SCRIPT_URL'; |
||
| 23 | } |
||
| 24 | |||
| 25 | $value = $default; |
||
| 26 | if (isset($_SERVER[$key])) { |
||
| 27 | $value = $_SERVER[$key]; |
||
| 28 | } elseif (isset($_ENV[$key])) { |
||
| 29 | $value = $_ENV[$key]; |
||
| 30 | } elseif (getenv($key) !== false) { |
||
| 31 | $value = getenv($key); |
||
| 32 | } |
||
| 33 | |||
| 34 | if ($value === null) { |
||
| 35 | return self::returnDefault($key, $default); |
||
| 36 | } |
||
| 37 | |||
| 38 | switch (strtolower($value)) { |
||
| 39 | case 'true': |
||
| 40 | case '(true)': |
||
| 41 | return true; |
||
| 42 | case 'false': |
||
| 43 | case '(false)': |
||
| 44 | return false; |
||
| 45 | case 'empty': |
||
| 46 | case '(empty)': |
||
| 47 | return ''; |
||
| 48 | case 'null': |
||
| 49 | case '(null)': |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | // if (strlen($value) > 1 && Str::startsWith($value, '"') && Str::endsWith($value, '"')) { |
||
| 53 | // return substr($value, 1, -1); |
||
| 54 | // } |
||
| 55 | |||
| 56 | return $value; |
||
| 57 | } |
||
| 85 | } |