Test Setup Failed
Push — master ( 82bc16...cbe1a2 )
by Alec
03:13
created

Formattable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getFormatter() 0 3 1
A __toString() 0 6 2
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
    public function __construct(FormatterInterface $formatter = null)
13
    {
14
        $this->formatter = $formatter;
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
32
    {
33
        return $this->formatter;
34
    }
35
}
36