CsvReaderFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 65
rs 10
c 0
b 0
f 0
ccs 14
cts 14
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A getReader() 0 11 2
1
<?php
2
3
namespace Ddeboer\DataImport\Reader\Factory;
4
5
use Ddeboer\DataImport\Reader\CsvReader;
6
7
/**
8
 * Factory that creates CsvReaders
9
 *
10
 * @author David de Boer <[email protected]>
11
 */
12
class CsvReaderFactory
13
{
14
    /**
15
     * @var integer
16
     */
17
    protected $headerRowNumber;
18
19
    /**
20
     * @var boolean
21
     */
22
    protected $strict;
23
24
    /**
25
     * @var string
26
     */
27
    protected $delimiter;
28
29
    /**
30
     * @var string
31
     */
32
    protected $enclosure;
33
34
    /**
35
     * @var string
36
     */
37
    protected $escape;
38
39
    /**
40
     * @param integer $headerRowNumber
41
     * @param boolean $strict
42
     * @param string  $delimiter
43
     * @param string  $enclosure
44
     * @param string  $escape
45
     */
46 1
    public function __construct(
47
        $headerRowNumber = null,
48
        $strict = true,
49
        $delimiter = ',',
50
        $enclosure = '"',
51
        $escape = '\\'
52
    ) {
53 1
        $this->headerRowNumber = $headerRowNumber;
54 1
        $this->strict = $strict;
55 1
        $this->delimiter = $delimiter;
56 1
        $this->enclosure = $enclosure;
57 1
        $this->escape = $escape;
58 1
    }
59
60
    /**
61
     * @param \SplFileObject $file
62
     *
63
     * @return CsvReader
64
     */
65 1
    public function getReader(\SplFileObject $file)
66
    {
67 1
        $reader = new CsvReader($file, $this->delimiter, $this->enclosure, $this->escape);
68 1
        if (null !== $this->headerRowNumber) {
69 1
            $reader->setHeaderRowNumber($this->headerRowNumber);
70 1
        }
71
72 1
        $reader->setStrict($this->strict);
73
74 1
        return $reader;
75
    }
76
}
77