Conditions | 5 |
Paths | 3 |
Total Lines | 29 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Tests | 18 |
CRAP Score | 5 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
23 | 5 | protected function extractFileContent($filepath) |
|
24 | { |
||
25 | 5 | $file = new \SplFileObject($filepath); |
|
26 | |||
27 | //csv file have to be formatted with headers on the first line |
||
28 | 5 | $headers = $file->fgetcsv(); |
|
29 | 5 | $nbHeaders = count($headers); |
|
30 | |||
31 | 5 | $datas = []; |
|
32 | 5 | while (!$file->eof()) { |
|
33 | 4 | $csvData = $file->fgetcsv(); |
|
34 | 4 | if (count($csvData) != $nbHeaders) { |
|
35 | 2 | continue; |
|
36 | } |
||
37 | //Handle many relations |
||
38 | 4 | $csvData = array_map(function ($e) { |
|
39 | 4 | if (strpos($e, '|') !== false) { |
|
40 | 2 | if (strlen($e) == 1) { |
|
41 | 2 | return []; |
|
42 | } |
||
43 | 2 | return explode('|', $e); |
|
44 | } |
||
45 | 4 | return $e; |
|
46 | 4 | }, $csvData); |
|
47 | |||
48 | 4 | $datas[] = array_combine($headers, $csvData); |
|
49 | } |
||
50 | |||
51 | 5 | return $datas; |
|
52 | } |
||
54 |