Total Complexity | 7 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
9 | class CsvHandler extends MimeHandlerAdapter |
||
10 | { |
||
11 | /** |
||
12 | * @param string $body |
||
13 | * @return mixed |
||
14 | * @throws \Exception |
||
15 | */ |
||
16 | public function parse($body) |
||
17 | { |
||
18 | if (empty($body)) |
||
19 | return null; |
||
20 | |||
21 | $parsed = array(); |
||
22 | $fp = fopen('data://text/plain;base64,' . base64_encode($body), 'r'); |
||
23 | while (($r = fgetcsv($fp)) !== FALSE) { |
||
|
|||
24 | $parsed[] = $r; |
||
25 | } |
||
26 | |||
27 | if (empty($parsed)) |
||
28 | throw new \Exception("Unable to parse response as CSV"); |
||
29 | return $parsed; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * @param mixed $payload |
||
34 | * @return string |
||
35 | */ |
||
36 | public function serialize($payload) |
||
50 | } |
||
51 | } |
||
52 |