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

CsvLoader::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
nc 2
cc 2
nop 1
crap 2
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