Completed
Push — master ( db5ad0...ac6025 )
by Andy
06:43
created

AbstractNormalizer::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Palmtree\Csv\Normalizer;
4
5
abstract class AbstractNormalizer implements NormalizerInterface
6
{
7
    /** @var NormalizerInterface */
8
    protected $normalizer;
9
10
    /**
11
     * AbstractNormalizer constructor.
12
     *
13
     * @param null|NormalizerInterface $normalizer
14
     */
15 7
    public function __construct($normalizer = null)
16
    {
17 7
        if (!$normalizer instanceof NormalizerInterface) {
18 7
            $normalizer = new NullNormalizer();
19
        }
20
21 7
        $this->setNormalizer($normalizer);
22 7
    }
23
24
    /**
25
     * @param string $value
26
     *
27
     * @return mixed
28
     */
29
    abstract protected function getNormalizedValue($value);
30
31
    /**
32
     * @inheritdoc
33
     */
34 7
    public function normalize($value)
35
    {
36 7
        $value = $this->getNormalizer()->normalize($value);
37
38 7
        $value = $this->getNormalizedValue($value);
39
40 7
        return $value;
41
    }
42
43
    /**
44
     * @param NormalizerInterface $normalizer
45
     *
46
     * @return AbstractNormalizer
47
     */
48 7
    public function setNormalizer(NormalizerInterface $normalizer)
49
    {
50 7
        $this->normalizer = $normalizer;
51
52 7
        return $this;
53
    }
54
55
    /**
56
     * @return NormalizerInterface
57
     */
58 7
    public function getNormalizer()
59
    {
60 7
        return $this->normalizer;
61
    }
62
}
63