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

AbstractFormatter::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

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