Conditions | 4 |
Paths | 7 |
Total Lines | 19 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4.1967 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
40 | 9 | public function asCsvLine(): string |
|
41 | { |
||
42 | 9 | $csvStream = fopen('php://memory', 'rb+'); |
|
43 | 9 | if ($csvStream === false) { |
|
44 | throw new \RuntimeException('Could not open temporary stream'); |
||
45 | } |
||
46 | try { |
||
47 | 9 | if (fputcsv($csvStream, $this->asArray()) === false) { |
|
48 | throw new \RuntimeException('Could not format TimerEvent as CSV'); |
||
49 | } |
||
50 | 9 | rewind($csvStream); |
|
51 | 9 | $line = stream_get_contents($csvStream); |
|
52 | 9 | if ($line === false) { |
|
53 | throw new \RuntimeException('Could not read from temporary CSV stream'); |
||
54 | } |
||
55 | 9 | } finally { |
|
56 | 9 | fclose($csvStream); |
|
57 | } |
||
58 | 9 | return rtrim($line); |
|
59 | } |
||
61 |