EasyCsvWriterAdapter::writeRow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2015-05-16 
5
 */
6
7
namespace Net\Bazzline\Component\Csv\Writer;
8
9
class EasyCsvWriterAdapter
10
{
11
    /** @var Writer|WriterForPhp5Dot3|WriterInterface  */
12
    private $writer;
13
14
    /**
15
     * @param string $path
16
     * @param string $mode - is not used
17
     * @param null|WriterInterface $writer - optional
18
     */
19
    public function __construct($path, $mode = 'r+', WriterInterface $writer = null)
20
    {
21
        if (is_null($writer)) {
22
            $factory = new WriterFactory();
23
            $this->writer = $factory->create();
24
        } else {
25
            $this->writer = $writer;
26
        }
27
28
        $this->writer->setDelimiter(',');
29
        $this->writer->setEnclosure('"');
30
        $this->writer->setPath($path);
31
    }
32
33
    /**
34
     * @param string $delimiter
35
     */
36
    public function setDelimiter($delimiter)
37
    {
38
        $this->writer->setDelimiter($delimiter);
39
    }
40
41
    /**
42
     * @param string $enclosure
43
     */
44
    public function setEnclosure($enclosure)
45
    {
46
        $this->writer->setEnclosure($enclosure);
47
    }
48
49
    /**
50
     * @param mixed $row
51
     * @return false|int
52
     */
53
    public function writeRow($row)
54
    {
55
        return $this->writer->writeOne($row);
56
    }
57
58
    /**
59
     * @param array $array
60
     */
61
    public function writeFromArray(array $array)
62
    {
63
        $this->writer->writeMany($array);
64
    }
65
}