| Total Complexity | 4 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 7 | abstract class Formattable |
||
| 8 | { |
||
| 9 | /** @var null|FormatterInterface */ |
||
| 10 | protected $formatter; |
||
| 11 | |||
| 12 | public function __construct(FormatterInterface $formatter = null) |
||
| 15 | } |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @return string |
||
| 19 | */ |
||
| 20 | public function __toString(): string |
||
| 21 | { |
||
| 22 | if ($this->formatter instanceof FormatterInterface) { |
||
| 23 | return $this->formatter->format($this); |
||
| 24 | } |
||
| 25 | return get_class($this) . ' ERROR: no formatter'; |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @return null|FormatterInterface |
||
| 30 | */ |
||
| 31 | public function getFormatter(): ?FormatterInterface |
||
| 34 | } |
||
| 35 | } |
||
| 36 |