Completed
Push — master ( d88042...0c5536 )
by Nicolas
02:25 queued 48s
created

CsvEntityExtractor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 30
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileExtension() 0 4 1
A extractFileContent() 0 14 2
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 1
    protected function getFileExtension()
16
    {
17 1
        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
30 1
        $data = [];
31 1
        while (!$file->eof()) {
32 1
            $data[] = array_combine($headers, $file->fgetcsv());
33
        }
34
35 1
        return $data;
36
    }
37
}
38