Conditions | 4 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4 |
Changes | 0 |
1 | <?php |
||
56 | 1 | public static function dataToCsv( |
|
57 | array $data, |
||
58 | string $separator = ",", |
||
59 | string $enclosure = '"', |
||
60 | string $escape = "\\" |
||
61 | ): string { |
||
62 | 1 | $f = fopen('php://memory', 'r+'); |
|
63 | 1 | if (!$f) { |
|
|
|||
64 | throw new Exception('Failed to convert data to csv'); // @codeCoverageIgnore |
||
65 | } |
||
66 | 1 | foreach ($data as $row) { |
|
67 | 1 | fputcsv($f, $row, $separator, $enclosure, $escape); |
|
68 | } |
||
69 | 1 | rewind($f); |
|
70 | |||
71 | 1 | $content = stream_get_contents($f); |
|
72 | 1 | if ($content === false) { |
|
73 | throw new Exception('Failed to convert data to csv'); // @codeCoverageIgnore |
||
74 | } |
||
75 | 1 | fclose($f); |
|
76 | |||
77 | 1 | return $content; |
|
78 | } |
||
79 | } |