Completed
Push — master ( 42b9a4...be55e6 )
by Marcus
01:28
created

LeagueCsvParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace MarcusJaschen\Collmex\Csv;
4
use League\Csv\Reader;
5
6
/**
7
 * CSV Parser Implementation using Keboola CSV Reader
8
 *
9
 * @author   Marcus Jaschen <[email protected]>
10
 * @license  http://www.opensource.org/licenses/mit-license MIT License
11
 * @link     https://github.com/mjaschen/collmex
12
 * @link     https://github.com/keboola/php-csv
13
 */
14
class LeagueCsvParser implements ParserInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $delimiter;
20
21
    /**
22
     * @var string
23
     */
24
    protected $enclosure;
25
26
    /**
27
     * @param string $delimiter
28
     * @param string $enclosure
29
     */
30
    public function __construct($delimiter = ';', $enclosure = '"')
31
    {
32
        $this->delimiter = $delimiter;
33
        $this->enclosure = $enclosure;
34
    }
35
36
    /**
37
     * @param string $csv one or multiple lines of CSV data
38
     *
39
     * @return array
40
     *
41
     * @throws \InvalidArgumentException
42
     */
43
    public function parse($csv)
44
    {
45
        $input = Reader::createFromString($csv);
46
47
        $input->setDelimiter($this->delimiter);
48
        $input->setEnclosure($this->enclosure);
49
50
        return $input->fetchAll();
51
    }
52
}
53