CsvFileWriter::write()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 3
nc 4
nop 3
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Zed\FactFinderSdk\Business\Writer;
9
10
class CsvFileWriter extends AbstractFileWriter implements FileWriterInterface
11
{
12
    public const DELIMITER = ',';
13
14
    /**
15
     * @param string $filePath
16
     * @param array $data
17
     * @param bool $append
18
     *
19
     * @return void
20
     */
21
    public function write($filePath, $data, $append = false)
22
    {
23
        $this->createDirectory($filePath);
24
25
        if ($append) {
26
            $filePointer = fopen($filePath, 'a');
27
        } else {
28
            $filePointer = fopen($filePath, 'w');
29
        }
30
31
        foreach ($data as $row) {
32
            fputcsv($filePointer, $row, static::DELIMITER);
33
        }
34
35
        fclose($filePointer);
36
    }
37
}
38