| Conditions | 14 |
| Paths | 12 |
| Total Lines | 34 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 14 | public function __invoke($filePath ,$key, $default = null) |
||
| 15 | { |
||
| 16 | if (file_exists($filePath . '.env')) { |
||
| 17 | $_dotenv = new Dotenv($filePath ); |
||
| 18 | $_dotenv->load(); |
||
| 19 | unset($_dotenv); |
||
| 20 | }else { |
||
| 21 | return ''; |
||
| 22 | } |
||
| 23 | $value = getenv($key); |
||
| 24 | |||
| 25 | if ($value === false) { |
||
| 26 | return $default; |
||
| 27 | } |
||
| 28 | switch (strtolower($value)) { |
||
|
|
|||
| 29 | case 'true': |
||
| 30 | case '(true)': |
||
| 31 | return true; |
||
| 32 | case 'false': |
||
| 33 | case '(false)': |
||
| 34 | return false; |
||
| 35 | case 'empty': |
||
| 36 | case '(empty)': |
||
| 37 | return ''; |
||
| 38 | case 'null': |
||
| 39 | case '(null)': |
||
| 40 | return null; |
||
| 41 | } |
||
| 42 | $strLen = strlen($value); |
||
| 43 | |||
| 44 | if ($strLen > 1 && $value[0] === '"' && $value[$strLen - 1] === '"') { |
||
| 45 | return substr($value, 1, -1); |
||
| 46 | } |
||
| 47 | return $value; |
||
| 48 | } |
||
| 49 | } |