Total Complexity | 5 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php declare(strict_types=1); |
||
7 | abstract class Formattable |
||
8 | { |
||
9 | /** @var null|FormatterInterface */ |
||
10 | protected $formatter; |
||
11 | |||
12 | 4 | public function __construct(FormatterInterface $formatter = null) |
|
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 |
|
34 | } |
||
35 | |||
36 | /** |
||
37 | * @param null|FormatterInterface $formatter |
||
38 | * @return Formattable |
||
39 | */ |
||
40 | 1 | public function setFormatter(?FormatterInterface $formatter): Formattable |
|
46 |