Completed
Pull Request — master (#10)
by Nicolas
01:54
created

CsvEntityExtractor::extractFileContent()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0067

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
ccs 10
cts 11
cp 0.9091
rs 9.6333
cc 3
nc 3
nop 1
crap 3.0067
1
<?php
2
3
namespace Smart\EtlBundle\Extractor;
4
5
/**
6
 * Nicolas Bastien <[email protected]>
7
 */
8
class CsvEntityExtractor extends AbstractFolderExtrator implements ExtractorInterface
9
{
10
    use EntityExtractorTrait;
11
12
    /**
13
     * @inheritDoc
14
     */
15 2
    protected function getFileExtension()
16
    {
17 2
        return 'csv';
18
    }
19
20
    /**
21
     * @inheritDoc
22
     */
23 1
    protected function extractFileContent($filepath)
24
    {
25 1
        $file = new \SplFileObject($filepath);
26
27
        //csv file have to be formatted with headers on the first line
28 1
        $headers = $file->fgetcsv();
29 1
        $nbHeaders = count($headers);
30
31 1
        $datas = [];
32 1
        while (!$file->eof()) {
33 1
            $csvData = $file->fgetcsv();
34 1
            if (count($csvData) != $nbHeaders) {
35
                continue;
36
            }
37 1
            $datas[] = array_combine($headers, $csvData);
38
        }
39
40 1
        return $datas;
41
    }
42
}
43