CsvFileWriter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 10
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A write() 0 15 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