Completed
Push — master ( b9c00d...f6b908 )
by Andrew
02:09
created

Parser::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CsvParser;
4
5
class Parser
6
{
7
    public $fieldDelimiter = ',';
8
    public $fieldEnclosure = '"';
9
    public $lineDelimiter = "\n";
10
11 17
    public function __construct($fieldDelimiter = null, $fieldEnclosure = null, $lineDelimiter = null)
12
    {
13 17
        if ( ! is_null($fieldDelimiter)) {
14 5
            $this->fieldDelimiter = $fieldDelimiter;
15 5
        }
16 17
        if ( ! is_null($fieldEnclosure)) {
17 5
            $this->fieldEnclosure = $fieldEnclosure;
18 5
        }
19 17
        if ( ! is_null($lineDelimiter)) {
20
            $this->lineDelimiter = $lineDelimiter;
21
        }
22 17
    }
23
24
    /* Readers */
25
26 11
    public function fromString($string)
27
    {
28 11
        return Reader\StringReader::read($this, $string);
29
    }
30
31 6
    public function fromArray($array)
32
    {
33 6
        return Reader\ArrayReader::read($this, $array);
34
    }
35
36
    public function fromFile($file)
37
    {
38
        return Reader\FileReader::read($this, $file);
39
    }
40
41
    /* Writers */
42
43 3
    public function toString(Csv $csv)
44 1
    {
45 3
        return Writer\StringWriter::write($this, $csv);
46
    }
47
48 9
    public function toArray(Csv $csv)
49
    {
50 9
        return Writer\ArrayWriter::write($this, $csv);
51
    }
52
53
    public function toFile(Csv $csv, $filename)
54
    {
55
        return Writer\FileWriter::write($this, $csv, $filename);
56
    }
57
58
    /* Special writers */
59
60
    public function toChunks(Csv $csv, $size=1000)
61
    {
62
        return Writer\ChunksWriter::write($this, $csv, $size);
63
    }
64
65
}
66