Passed
Push — master ( 25c805...999286 )
by Andy
02:56 queued 11s
created

StringNormalizer::shouldTrim()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Palmtree\Csv\Normalizer;
4
5
/**
6
 * StringNormalizer formats a CSV cell as a string.
7
 * It will trim the string by default.
8
 */
9
class StringNormalizer extends AbstractNormalizer
10
{
11
    /** @var bool */
12
    private $trim = true;
13
    /** @var string */
14
    private $trimCharMask = " \t\n\r\0\x0B";
15
16 2
    public function setTrim(bool $trim): self
17
    {
18 2
        $this->trim = $trim;
19
20 2
        return $this;
21
    }
22
23 1
    public function setTrimCharMask(string $trimCharMask): self
24
    {
25 1
        $this->trimCharMask = $trimCharMask;
26
27 1
        return $this;
28
    }
29
30 2
    public function getTrimCharMask(): string
31
    {
32 2
        return $this->trimCharMask;
33
    }
34
35
    public function shouldTrim(): bool
36
    {
37
        return $this->trim;
38
    }
39
40 3
    protected function getNormalizedValue(string $value): string
41
    {
42 3
        if ($this->trim) {
43 2
            $value = \trim($value, $this->getTrimCharMask());
44
        }
45
46 3
        return $value;
47
    }
48
}
49