Csv   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A writer() 0 8 1
A __construct() 0 10 1
A reader() 0 8 1
1
<?php
2
3
namespace Tleckie\Csv;
4
5
use Tleckie\Csv\Reader\ReaderInterface;
6
use Tleckie\Csv\Writer\WriterInterface;
7
8
/**
9
 * Class Csv
10
 *
11
 * @package Tleckie\Csv
12
 * @author  Teodoro Leckie Westberg <[email protected]>
13
 */
14
class Csv implements CsvInterface
15
{
16
    /** @var string */
17
    protected string $file;
18
19
    /** @var string */
20
    protected string $separator;
21
22
    /** @var string */
23
    protected string $enclosure;
24
25
    /** @var string */
26
    protected string $escape;
27
28
    /**
29
     * Reader constructor.
30
     *
31
     * @param string $file
32
     * @param string $separator
33
     * @param string $enclosure
34
     * @param string $escape
35
     */
36
    public function __construct(
37
        string $file,
38
        string $separator = ',',
39
        string $enclosure = '"',
40
        string $escape = "\\",
41
    ) {
42
        $this->file = $file;
43
        $this->separator = $separator;
44
        $this->enclosure = $enclosure;
45
        $this->escape = $escape;
46
    }
47
48
    /**
49
     * @inheritdoc
50
     */
51
    public function writer(string $mode = 'a+'): WriterInterface
52
    {
53
        return new Writer(
54
            $this->file,
55
            $this->separator,
56
            $this->enclosure,
57
            $this->escape,
58
            $mode
59
        );
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    public function reader(string $mode = 'r'): ReaderInterface
66
    {
67
        return new Reader(
68
            $this->file,
69
            $this->separator,
70
            $this->enclosure,
71
            $this->escape,
72
            $mode
73
        );
74
    }
75
}
76