Conditions | 5 |
Paths | 7 |
Total Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Tests | 16 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
32 | 8 | public function save(array $answers) |
|
33 | { |
||
34 | 8 | $path = $this->directory . DIRECTORY_SEPARATOR . $this->file; |
|
35 | |||
36 | 8 | if (!file_exists($path)) { |
|
37 | 6 | if (!is_writable($this->directory)) { |
|
38 | 4 | throw new WritableException( |
|
39 | 4 | sprintf( |
|
40 | 4 | 'The env file is not present and the directory `%s` is not writeable!', |
|
41 | 4 | $this->directory |
|
42 | ) |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | 2 | touch($path); |
|
47 | } |
||
48 | |||
49 | 4 | if (!is_writable($path)) { |
|
50 | 2 | throw new WritableException(sprintf('The env file `%s` is not writeable!', $path)); |
|
51 | } |
||
52 | |||
53 | 2 | $text = ''; |
|
54 | 2 | foreach ($answers as $key => $value) { |
|
55 | 2 | $text .= sprintf("%s=%s\n", $key, $value); |
|
56 | } |
||
57 | |||
58 | 2 | file_put_contents($path, $text); |
|
59 | 2 | } |
|
60 | } |
||
61 |