Completed
Push — master ( afa401...19e2a9 )
by Andy
02:13
created

Cell   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
wmc 8
eloc 17
dl 0
loc 76
ccs 14
cts 21
cp 0.6667
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getRawValue() 0 3 1
A getValue() 0 3 1
A getNormalizer() 0 3 1
A __toString() 0 9 2
A __construct() 0 4 1
A setNormalizer() 0 5 1
A setRawValue() 0 5 1
1
<?php
2
3
namespace Palmtree\Csv\Cell;
4
5
use Palmtree\Csv\Normalizer\NormalizerInterface;
6
7
class Cell
8
{
9
    /** @var NormalizerInterface $normalizer */
10
    private $normalizer;
11
    /** @var string */
12
    private $value;
13
14
    /**
15
     * Cell constructor.
16
     *
17
     * @param string              $value
18
     * @param NormalizerInterface $normalizer
19
     */
20 9
    public function __construct($value, NormalizerInterface $normalizer)
21
    {
22 9
        $this->setRawValue($value);
23 9
        $this->setNormalizer($normalizer);
24 9
    }
25
26
    /**
27
     * @return string
28
     */
29 7
    public function getRawValue()
30
    {
31 7
        return $this->value;
32
    }
33
34
    /**
35
     * @return mixed
36
     */
37 7
    public function getValue()
38
    {
39 7
        return $this->normalizer->normalize($this->getRawValue());
40
    }
41
42
    /**
43
     * @return NormalizerInterface
44
     */
45
    public function getNormalizer()
46
    {
47
        return $this->normalizer;
48
    }
49
50
    /**
51
     * @param NormalizerInterface $normalizer
52
     *
53
     * @return Cell
54
     */
55 9
    public function setNormalizer(NormalizerInterface $normalizer)
56
    {
57 9
        $this->normalizer = $normalizer;
58
59 9
        return $this;
60
    }
61
62
    public function __toString()
63
    {
64
        try {
65
            $value = (string)$this->getValue();
66
        } catch (\Exception $exception) {
67
            $value = '';
68
        }
69
70
        return $value;
71
    }
72
73
    /**
74
     * @param mixed $value
75
     *
76
     * @return Cell
77
     */
78 9
    public function setRawValue($value)
79
    {
80 9
        $this->value = $value;
81
82 9
        return $this;
83
    }
84
}
85