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