Passed
Branch master (9671df)
by Andy
02:10
created

Cell::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Palmtree\Csv\Cell;
4
5
use Palmtree\Csv\Formatter\FormatterInterface;
6
7
class Cell
8
{
9
    /** @var FormatterInterface $formatter */
10
    protected $formatter;
11
    protected $value;
12
13
    /**
14
     * Cell constructor.
15
     *
16
     * @param                         $value
17
     * @param FormatterInterface      $formatter
18
     */
19 4
    public function __construct($value, FormatterInterface $formatter)
20
    {
21 4
        $this->setRawValue($value);
22 4
        $this->setFormatter($formatter);
23 4
    }
24
25
    /**
26
     * @return string
27
     */
28 2
    public function getRawValue()
29
    {
30 2
        return $this->value;
31
    }
32
33
    /**
34
     * @return mixed
35
     */
36 2
    public function getValue()
37
    {
38 2
        return $this->getFormatter()->format($this->getRawValue());
39
    }
40
41
    /**
42
     * @return FormatterInterface
43
     */
44 2
    public function getFormatter()
45
    {
46 2
        return $this->formatter;
47
    }
48
49
    /**
50
     * @param FormatterInterface $formatter
51
     *
52
     * @return Cell
53
     */
54 4
    public function setFormatter(FormatterInterface $formatter)
55
    {
56 4
        $this->formatter = $formatter;
57
58 4
        return $this;
59
    }
60
61
    public function __toString()
62
    {
63
        try {
64
            $value = (string)$this->getValue();
65
        } catch (\Exception $exception) {
66
            $value = '';
67
        }
68
69
        return $value;
70
    }
71
72
    /**
73
     * @param mixed $value
74
     *
75
     * @return Cell
76
     */
77 4
    public function setRawValue($value)
78
    {
79 4
        $this->value = $value;
80
81 4
        return $this;
82
    }
83
}
84