| Conditions | 13 |
| Paths | 11 |
| Total Lines | 28 |
| Code Lines | 19 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 13 |
| 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 |
||
| 11 | function env($key, $default = null) |
||
| 12 | { |
||
| 13 | 163 | $value = getenv($key); |
|
| 14 | |||
| 15 | 163 | if ($value === false) { |
|
| 16 | 37 | return value($default); |
|
| 17 | } |
||
| 18 | |||
| 19 | 127 | switch (strtolower($value)) { |
|
| 20 | 127 | case 'true': |
|
| 21 | 127 | case '(true)': |
|
| 22 | 1 | return true; |
|
| 23 | 127 | case 'false': |
|
| 24 | 127 | case '(false)': |
|
| 25 | 125 | return false; |
|
| 26 | 3 | case 'empty': |
|
| 27 | 3 | case '(empty)': |
|
| 28 | 1 | return ''; |
|
| 29 | 3 | case 'null': |
|
| 30 | 3 | case '(null)': |
|
| 31 | 1 | return; |
|
| 32 | 2 | } |
|
| 33 | |||
| 34 | 2 | if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') { |
|
| 35 | 1 | return substr($value, 1, -1); |
|
| 36 | } |
||
| 37 | |||
| 38 | 2 | return $value; |
|
| 39 | } |
||
| 55 |