Conditions | 14 |
Paths | 12 |
Total Lines | 31 |
Code Lines | 21 |
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 |
||
40 | public function get($key = '', $default = null) |
||
41 | { |
||
42 | if (!strlen($key)) { // 不传key则返回所有环境变量 |
||
43 | return $this->allValues; |
||
44 | } |
||
45 | |||
46 | $value = getenv($key); |
||
47 | if ($value === false) { |
||
48 | return $default; |
||
49 | } |
||
50 | |||
51 | switch (strtolower($value)) { |
||
52 | case 'true': |
||
53 | case '(true)': |
||
54 | return true; |
||
55 | case 'false': |
||
56 | case '(false)': |
||
57 | return false; |
||
58 | case 'empty': |
||
59 | case '(empty)': |
||
60 | return ''; |
||
61 | case 'null': |
||
62 | case '(null)': |
||
63 | return null; |
||
64 | } |
||
65 | |||
66 | if (($valueLength = strlen($value)) > 1 && $value[0] === '"' && $value[$valueLength - 1] === '"') { // 去除双引号 |
||
67 | return substr($value, 1, -1); |
||
68 | } |
||
69 | |||
70 | return $value; |
||
71 | } |
||
72 | } |