Formattable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 37
ccs 12
cts 12
cp 1
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getFormatter() 0 3 1
A __toString() 0 6 2
A setFormatter() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Reports\Core;
4
5
use AlecRabbit\Formatters\Contracts\FormatterInterface;
6
7
abstract class Formattable
8
{
9
    /** @var null|FormatterInterface */
10
    protected $formatter;
11
12 4
    public function __construct(FormatterInterface $formatter = null)
13
    {
14 4
        $this->formatter = $formatter;
15 4
    }
16
17
    /**
18
     * @return string
19
     */
20 3
    public function __toString(): string
21
    {
22 3
        if ($this->formatter instanceof FormatterInterface) {
23 3
            return $this->formatter->format($this);
24
        }
25 1
        return get_class($this) . ' ERROR: no formatter';
26
    }
27
28
    /**
29
     * @return null|FormatterInterface
30
     */
31 4
    public function getFormatter(): ?FormatterInterface
32
    {
33 4
        return $this->formatter;
34
    }
35
36
    /**
37
     * @param null|FormatterInterface $formatter
38
     * @return Formattable
39
     */
40 1
    public function setFormatter(?FormatterInterface $formatter): Formattable
41
    {
42 1
        $this->formatter = $formatter;
43 1
        return $this;
44
    }
45
}
46