Conditions | 11 |
Paths | 20 |
Total Lines | 29 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
77 | public static function get($key, $default = null) |
||
78 | { |
||
79 | $value = Environment::getRepositoryCreator()->get($key); |
||
80 | |||
81 | if ($value === null) { |
||
82 | $value = $_ENV[$key] ?? $_SERVER[$key] ?? false; |
||
83 | } |
||
84 | |||
85 | if ($value === false) { |
||
86 | return value($default); |
||
87 | } |
||
88 | |||
89 | // Handle any boolean values |
||
90 | switch (strtolower($value)) { |
||
91 | case 'true': |
||
92 | case '(true)': |
||
93 | return true; |
||
94 | case 'false': |
||
95 | case '(false)': |
||
96 | return false; |
||
97 | case 'empty': |
||
98 | case '(empty)': |
||
99 | return ''; |
||
100 | case 'null': |
||
101 | case '(null)': |
||
102 | return null; |
||
103 | } |
||
104 | |||
105 | return $value; |
||
106 | } |
||
107 | } |