Completed
Push — master ( ba86a8...110e22 )
by Alec
04:16 queued 41s
created

Report   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 21
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A wrongReportable() 0 4 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Tools\Reports\Core;
4
5
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
6
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
7
use AlecRabbit\Tools\Reports\Formatters\Contracts\FormatterInterface;
8
use function AlecRabbit\typeOf;
9
10
abstract class Report implements ReportInterface
11
{
12
    abstract public function buildOn(ReportableInterface $reportable): ReportInterface;
13
14
    /** {@inheritdoc} */
15 16
    public function __toString(): string
16
    {
17
        return
18 16
            static::getFormatter()->process($this);
19
    }
20
21
    abstract protected static function getFormatter(): FormatterInterface;
22
23
    /**
24
     * @param string $expected
25
     * @param ReportableInterface $reportable
26
     */
27 5
    protected function wrongReportable(string $expected, ReportableInterface $reportable): void
28
    {
29 5
        throw new \RuntimeException(
30 5
            'Instance of [' . $expected . '] expected, [' . typeOf($reportable) . '] given'
31
        );
32
    }
33
}
34