Passed
Branch feature/php7 (3e8a2f)
by Andy
04:54
created

ArrayNormalizer::setDelimiter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Palmtree\Csv\Normalizer;
4
5
class ArrayNormalizer extends AbstractNormalizer
6
{
7
    /** @var string */
8
    private $delimiter;
9
    /** @var StringNormalizer */
10
    private $stringNormalizer;
11
12 1
    public function __construct(NormalizerInterface $normalizer = null, string $delimiter = ',')
13
    {
14 1
        $this->setDelimiter($delimiter);
15
16 1
        $this->stringNormalizer = new StringNormalizer();
17 1
        $this->stringNormalizer->setTrimCharMask($this->stringNormalizer->getTrimCharMask() . $this->delimiter);
18
19 1
        parent::__construct($normalizer);
20 1
    }
21
22 1
    public function normalize(string $value)
23
    {
24 1
        return $this->getNormalizedValue($value);
25
    }
26
27 1
    protected function getNormalizedValue(string $value)
28
    {
29 1
        $value           = $this->stringNormalizer->normalize($value);
30 1
        $normalizedValue = \explode($this->delimiter, $value);
31
32 1
        foreach ($normalizedValue as &$part) {
33 1
            $part = $this->normalizer->normalize($part);
0 ignored issues
show
Bug introduced by
The method normalize() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

33
            /** @scrutinizer ignore-call */ 
34
            $part = $this->normalizer->normalize($part);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
        }
35
36 1
        return $normalizedValue;
37
    }
38
39 1
    public function setDelimiter(string $delimiter): self
40
    {
41 1
        $this->delimiter = $delimiter;
42
43 1
        return $this;
44
    }
45
46
    public function getDelimiter(): string
47
    {
48
        return $this->delimiter;
49
    }
50
}
51