Conditions | 5 |
Paths | 5 |
Total Lines | 31 |
Code Lines | 18 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 5.0073 |
Changes | 0 |
1 | <?php |
||
16 | 13 | public function parse($path) |
|
17 | { |
||
18 | 13 | if (!is_file($path)) { |
|
19 | 1 | throw new InvalidArgumentException(sprintf('The file "%s" does not exist', $path)); |
|
20 | } |
||
21 | |||
22 | 12 | $file = fopen($path, 'rb'); |
|
23 | |||
24 | 12 | $number = 0; |
|
25 | 12 | $env = []; |
|
26 | 12 | while (false === feof($file)) { |
|
27 | $line = trim(fgets($file)); |
||
28 | $number ++; |
||
29 | 12 | ||
30 | 10 | if ($this->isCommentOrEmpty($line)) { |
|
31 | continue; |
||
32 | 12 | } |
|
33 | if (false === strpos($line, '=')) { |
||
34 | throw new InvalidArgumentException( |
||
35 | sprintf('Parse error at %d line: `%s` is not valid env value', $number, $line) |
||
36 | 12 | ); |
|
37 | 12 | } |
|
38 | 12 | ||
39 | list($name, $value) = explode('=', $line, 2); |
||
40 | 12 | $env[trim($name)] = trim($value); |
|
41 | } |
||
42 | |||
43 | fclose($file); |
||
44 | |||
45 | return $env; |
||
46 | } |
||
47 | |||
58 |