Completed
Pull Request — master (#6)
by Chad
01:26
created

CsvOptions::getDelimiter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace SubjectivePHP\Csv;
4
5
final class CsvOptions
6
{
7
    /**
8
     * @var string
9
     */
10
    private $delimiter;
11
12
    /**
13
     * @var string
14
     */
15
    private $enclosure;
16
17
    /**
18
     * @var string
19
     */
20
    private $escapeChar;
21
22
    /**
23
     * Construct a new CsvOptions instance.
24
     *
25
     * @param string $delimiter The field delimiter (one character only).
26
     * @param string $enclosure The field enclosure character (one character only).
27
     * @param string $escapeChar The escape character (one character only).
28
     */
29
    public function __construct(string $delimiter = ',', string $enclosure = '"', string $escapeChar = '\\')
30
    {
31
        if (strlen($delimiter) !== 1) {
32
            throw new \InvalidArgumentException('$delimiter must be a single character string');
33
        }
34
35
        if (strlen($enclosure) !== 1) {
36
            throw new \InvalidArgumentException('$enclosure must be a single character string');
37
        }
38
39
        if (strlen($escapeChar) !== 1) {
40
            throw new \InvalidArgumentException('$escapeChar must be a single character string');
41
        }
42
43
        $this->delimiter = $delimiter;
44
        $this->enclosure = $enclosure;
45
        $this->escapeChar = $escapeChar;
46
    }
47
48
    /**
49
     * Gets the field delimiter (one character only).
50
     *
51
     * @return string
52
     */
53
    public function getDelimiter() : string
54
    {
55
        return $this->delimiter;
56
    }
57
58
    /**
59
     * Gets the field enclosure character (one character only).
60
     *
61
     * @return string
62
     */
63
    public function getEnclosure() : string
64
    {
65
        return $this->enclosure;
66
    }
67
68
    /**
69
     * Gets the escape character (one character only).
70
     *
71
     * @return string
72
     */
73
    public function getEscapeChar() : string
74
    {
75
        return $this->escapeChar;
76
    }
77
78
}
79