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

Parser   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Test Coverage

Coverage 69.23%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 11
c 3
b 2
f 0
lcom 0
cbo 7
dl 0
loc 61
ccs 18
cts 26
cp 0.6923
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 4 1
A fromArray() 0 4 1
A fromFile() 0 4 1
A toArray() 0 4 1
A toFile() 0 4 1
A toChunks() 0 4 1
A __construct() 0 12 4
A toString() 0 4 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