CSV   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 35
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 9 2
A sanitize() 0 9 1
1
<?php
2
3
namespace MidasSoft\DominicanBankParser\Files;
4
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()
32
    {
33 12
        $csvArray = [];
34 12
        foreach ($this->sanitize() as $key => $line) {
35 12
            $actualLine = str_getcsv(strip_tags(stripslashes(trim($line))));
36 12
            $csvArray[] = array_filter($actualLine);
37
        }
38
39 12
        return array_values(array_filter($csvArray));
40
    }
41
}
42