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

CsvEntityExtractor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2
ccs 12
cts 13
cp 0.9231
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileExtension() 0 4 1
A extractFileContent() 0 19 3
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