Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
8 / 8 |
TxtGenerator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
4 | |
100.00% |
8 / 8 |
createFile | |
100.00% |
1 / 1 |
4 | |
100.00% |
8 / 8 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\FileGenerator\Services\FileGenerator\Generators; |
4 | |
5 | class TxtGenerator extends AbstractGenerator |
6 | { |
7 | /** |
8 | * @var array|string[] |
9 | */ |
10 | protected array $rules = [ |
11 | 'type' => 'required|in:txt', |
12 | 'content' => 'required' |
13 | ]; |
14 | |
15 | /** |
16 | * |
17 | */ |
18 | protected function createFile(): void |
19 | { |
20 | if (is_string($this->config->content)) { |
21 | file_put_contents($this->config->output_path, $this->config->content); |
22 | } |
23 | |
24 | if (is_array($this->config->content)) { |
25 | $fp = fopen($this->config->output_path, 'w+'); |
26 | |
27 | foreach ($this->config->content as $line) { |
28 | fwrite($fp, $line . PHP_EOL); |
29 | } |
30 | |
31 | fclose($fp); |
32 | } |
33 | } |
34 | } |