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

CsvLoader   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 32
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 6 2
A processFile() 0 15 3
1
<?php
2
3
namespace Smart\EtlBundle\Loader;
4
5
/**
6
 * Nicolas Bastien <[email protected]>
7
 */
8
class CsvLoader extends AbstractFileLoader implements LoaderInterface
9
{
10
    /**
11
     * @inheritDoc
12
     */
13 1
    public function load(array $data)
14
    {
15 1
        foreach ($data as $filename => $fileData) {
16 1
            $this->processFile($filename, $fileData);
17
        }
18 1
    }
19
20
    /**
21
     * @param string $filename
22
     * @param array $data
23
     */
24 1
    protected function processFile($filename, $data)
25
    {
26 1
        $filepath = $this->getFolderToLoad() . DIRECTORY_SEPARATOR . $filename . '.' . $this->fileExtension;
27 1
        if (!is_dir(dirname($filepath))) {
28 1
            mkdir(dirname($filepath), 0700, true);
29
        }
30 1
        $fp = fopen($filepath, 'w');
31
32
        //write headers
33 1
        fputcsv($fp, array_keys($data[0]), ',', '"');
34 1
        foreach ($data as $row) {
35 1
            fputcsv($fp, $row);
36
        }
37 1
        fclose($fp);
38 1
    }
39
}
40