Completed
Push — develop ( f10e50...4f888d )
by Alec
03:20
created

ReportFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 26
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A createReport() 0 19 5
1
<?php
2
/**
3
 * User: alec
4
 * Date: 01.12.18
5
 * Time: 17:14
6
 */
7
8
namespace AlecRabbit\Tools\Reports;
9
10
use AlecRabbit\Tools\Benchmark;
11
use AlecRabbit\Tools\Counter;
12
use AlecRabbit\Tools\Profiler;
13
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface;
14
use AlecRabbit\Tools\Reports\Contracts\ReportInterface;
15
use AlecRabbit\Tools\Timer;
16
use function AlecRabbit\typeOf;
17
18
class ReportFactory
19
{
20
21
    /**
22
     * @param ReportableInterface $reportable
23
     * @return ReportInterface
24
     */
25 8
    public static function createReport(ReportableInterface $reportable): ReportInterface
26
    {
27 8
        if ($reportable instanceof Timer) {
28
            return
29 7
                new TimerReport($reportable);
30
        }
31 6
        if ($reportable instanceof Counter) {
32
            return
33 6
                new CounterReport($reportable);
34
        }
35 5
        if ($reportable instanceof Profiler) {
36
            return
37 5
                new ProfilerReport($reportable);
38
        }
39 2
        if ($reportable instanceof Benchmark) {
40
            return
41 2
                new BenchmarkReport($reportable);
42
        }
43
        throw new \RuntimeException('Attempt to create unimplemented report: ' . typeOf($reportable));
44
    }
45
}
46