| Total Complexity | 3 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class CSV extends AbstractFile |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Eliminates all unnecesary |
||
| 9 | * values in a CSV file. |
||
| 10 | * |
||
| 11 | * @return array |
||
| 12 | */ |
||
| 13 | 12 | private function sanitize() |
|
| 14 | { |
||
| 15 | 12 | $fileWithoutEmptyLine = preg_replace('/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/', '\n', $this->fileContent); |
|
| 16 | 12 | $cleanedCsvAmounts = preg_replace('/,(?=[^\"]*\"[^\"]*(?:\"[^\"]*\"[^\"]*)*$)/', '', $fileWithoutEmptyLine); |
|
| 17 | 12 | $cleanedCsvAmounts = preg_replace('/[\"]+/', '', $cleanedCsvAmounts); |
|
| 18 | |||
| 19 | 12 | $lines = explode(PHP_EOL, $cleanedCsvAmounts); |
|
| 20 | |||
| 21 | 12 | return $lines; |
|
| 22 | } |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Converts a CSV string to array. |
||
| 26 | * |
||
| 27 | * @param string $csvString |
||
| 28 | * |
||
| 29 | * @return array |
||
| 30 | */ |
||
| 31 | 12 | public function toArray() |
|
| 40 | } |
||
| 41 | } |
||
| 42 |