| Conditions | 10 |
| Paths | 10 |
| Total Lines | 29 |
| Code Lines | 18 |
| 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 |
||
| 26 | function env($key, $default = null) |
||
| 27 | { |
||
| 28 | $value = getenv($key); |
||
| 29 | |||
| 30 | if ($value === false) { |
||
| 31 | return value($default); |
||
| 32 | } |
||
| 33 | |||
| 34 | switch (strtolower($value)) |
||
| 35 | { |
||
| 36 | case 'true': |
||
| 37 | case '(true)': |
||
| 38 | return true; |
||
| 39 | |||
| 40 | case 'false': |
||
| 41 | case '(false)': |
||
| 42 | return false; |
||
| 43 | |||
| 44 | case 'empty': |
||
| 45 | case '(empty)': |
||
| 46 | return ''; |
||
| 47 | |||
| 48 | case 'null': |
||
| 49 | case '(null)': |
||
| 50 | return; |
||
| 51 | } |
||
| 52 | |||
| 53 | return $value; |
||
| 54 | } |
||
| 55 | } |
||
| 56 |