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

AbstractFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 58
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
getFormattedValue() 0 1 ?
A __construct() 0 8 2
A format() 0 8 1
A setFormatter() 0 6 1
A getFormatter() 0 4 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