|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AlecRabbit\Tools\Reports; |
|
6
|
|
|
|
|
7
|
|
|
use AlecRabbit\Exception\InvalidStyleException; |
|
8
|
|
|
use AlecRabbit\Themed; |
|
9
|
|
|
use AlecRabbit\Tools\Benchmark; |
|
10
|
|
|
use AlecRabbit\Tools\Counter; |
|
11
|
|
|
use AlecRabbit\Tools\Profiler; |
|
12
|
|
|
use AlecRabbit\Tools\Reports\Contracts\ReportableInterface; |
|
13
|
|
|
use AlecRabbit\Tools\Reports\Contracts\ReportInterface; |
|
14
|
|
|
use AlecRabbit\Tools\Reports\Formatters\BenchmarkReportFormatter; |
|
15
|
|
|
use AlecRabbit\Tools\Reports\Formatters\Contracts\ReportFormatter; |
|
16
|
|
|
use AlecRabbit\Tools\Reports\Formatters\CounterReportFormatter; |
|
17
|
|
|
use AlecRabbit\Tools\Reports\Formatters\ProfilerReportFormatter; |
|
18
|
|
|
use AlecRabbit\Tools\Reports\Formatters\TimerReportFormatter; |
|
19
|
|
|
use AlecRabbit\Tools\Timer; |
|
20
|
|
|
use function AlecRabbit\typeOf; |
|
21
|
|
|
|
|
22
|
|
|
class Factory |
|
23
|
|
|
{ |
|
24
|
|
|
/** @codeCoverageIgnore */ |
|
25
|
|
|
private function __construct() |
|
26
|
|
|
{ |
|
27
|
|
|
// Static class |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param ReportableInterface $reportable |
|
32
|
|
|
* @return ReportInterface |
|
33
|
|
|
*/ |
|
34
|
13 |
|
public static function makeReport(ReportableInterface $reportable): ReportInterface |
|
35
|
|
|
{ |
|
36
|
13 |
|
if ($reportable instanceof Timer) { |
|
37
|
|
|
return |
|
38
|
10 |
|
new TimerReport($reportable); |
|
39
|
|
|
} |
|
40
|
8 |
|
if ($reportable instanceof Counter) { |
|
41
|
|
|
return |
|
42
|
7 |
|
new CounterReport($reportable); |
|
43
|
|
|
} |
|
44
|
6 |
|
if ($reportable instanceof Profiler) { |
|
45
|
|
|
return |
|
46
|
5 |
|
new ProfilerReport($reportable); |
|
47
|
|
|
} |
|
48
|
4 |
|
if ($reportable instanceof Benchmark) { |
|
49
|
|
|
return |
|
50
|
3 |
|
new BenchmarkReport($reportable); |
|
51
|
|
|
} |
|
52
|
1 |
|
throw new \RuntimeException('Attempt to create unimplemented report for: ' . typeOf($reportable)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param ReportInterface $report |
|
57
|
|
|
* @return ReportFormatter |
|
58
|
|
|
*/ |
|
59
|
13 |
|
public static function makeFormatter(ReportInterface $report): ReportFormatter |
|
60
|
|
|
{ |
|
61
|
13 |
|
if ($report instanceof TimerReport) { |
|
62
|
|
|
return |
|
63
|
10 |
|
new TimerReportFormatter($report); |
|
64
|
|
|
} |
|
65
|
8 |
|
if ($report instanceof CounterReport) { |
|
66
|
|
|
return |
|
67
|
7 |
|
new CounterReportFormatter($report); |
|
68
|
|
|
} |
|
69
|
6 |
|
if ($report instanceof ProfilerReport) { |
|
70
|
|
|
return |
|
71
|
5 |
|
new ProfilerReportFormatter($report); |
|
72
|
|
|
} |
|
73
|
4 |
|
if ($report instanceof BenchmarkReport) { |
|
74
|
|
|
return |
|
75
|
3 |
|
new BenchmarkReportFormatter($report); |
|
76
|
|
|
} |
|
77
|
1 |
|
throw new \RuntimeException('Attempt to create unimplemented formatter for: ' . typeOf($report)); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|