| Conditions | 7 |
| Paths | 6 |
| Total Lines | 34 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 56 |
| Changes | 0 | ||
| 1 | <?php |
||
| 41 | public function load(string $file): bool |
||
| 42 | { |
||
| 43 | if (!is_file($file)) { |
||
| 44 | return false; |
||
| 45 | } |
||
| 46 | |||
| 47 | $content = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
||
| 48 | |||
| 49 | foreach ($content as $line) { |
||
| 50 | $line = rtrim(ltrim($line)); |
||
| 51 | |||
| 52 | //check if the line contains a key value pair |
||
| 53 | if (!preg_match("/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/", $line)) { |
||
| 54 | continue; |
||
| 55 | } |
||
| 56 | |||
| 57 | [$key, $value] = explode('=', $line); |
||
| 58 | |||
| 59 | //set to empty value |
||
| 60 | if (strlen($value) === 0) { |
||
| 61 | putenv("{$key}="); |
||
| 62 | continue; |
||
| 63 | } |
||
| 64 | |||
| 65 | $edges = $value[0].$value[-1]; |
||
| 66 | |||
| 67 | if ($edges === "''" || $edges === '""') { |
||
| 68 | $value = substr($value, 1, -1); |
||
| 69 | } |
||
| 70 | |||
| 71 | putenv("{$key}={$value}"); |
||
| 72 | } |
||
| 73 | |||
| 74 | return true; |
||
| 75 | } |
||
| 77 |