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