| Conditions | 13 |
| Paths | 11 |
| Total Lines | 24 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 10 | function env(string $key, $default = null) |
||
| 11 | { |
||
| 12 | $value = getenv($key); |
||
| 13 | if ($value === false) { |
||
| 14 | return value($default); |
||
| 15 | } |
||
| 16 | switch (strtolower($value)) { |
||
| 17 | case 'true': |
||
| 18 | case '(true)': |
||
| 19 | return true; |
||
| 20 | case 'false': |
||
| 21 | case '(false)': |
||
| 22 | return false; |
||
| 23 | case 'empty': |
||
| 24 | case '(empty)': |
||
| 25 | return ''; |
||
| 26 | case 'null': |
||
| 27 | case '(null)': |
||
| 28 | return null; |
||
| 29 | } |
||
| 30 | if (($valueLength = strlen($value)) > 1 && strpos($value, '"') === 0 && $value[$valueLength - 1] === '"') { |
||
| 31 | return substr($value, 1, -1); |
||
| 32 | } |
||
| 33 | return $value; |
||
| 34 | } |
||
| 48 | } |