WriterFactory::getWriter()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2015-05-06 
5
 */
6
7
namespace Net\Bazzline\Component\Csv\Writer;
8
9
use Net\Bazzline\Component\Csv\AbstractFactory;
10
11
class WriterFactory extends AbstractFactory
12
{
13
    /**
14
     * @return Writer|WriterForPhp5Dot3|WriterInterface
15
     */
16
    public function create()
17
    {
18
        $writer = $this->getWriter();
19
20
        $writer->setDelimiter($this->getDelimiter());
21
        $writer->setEnclosure($this->getEnclosure());
22
        $writer->setEscapeCharacter($this->getEscapeCharacter());
23
24
        return $writer;
25
    }
26
27
    /**
28
     * @return Writer|WriterForPhp5Dot3|WriterInterface
29
     */
30
    protected function getWriter()
31
    {
32
        if ($this->phpVersionLessThen5Dot4()) {
33
            $writer = new WriterForPhp5Dot3();
34
        } else {
35
            $writer = new Writer();
36
        }
37
38
        return $writer;
39
    }
40
41
    /**
42
     * @return boolean
43
     */
44
    protected function phpVersionLessThen5Dot4()
45
    {
46
        return (version_compare(phpversion(), '5.4', '<'));
47
    }
48
}