|
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\Reports\Formatters\BenchmarkReportFormatter; |
|
16
|
|
|
use AlecRabbit\Tools\Reports\Formatters\Contracts\ReportFormatter; |
|
17
|
|
|
use AlecRabbit\Tools\Timer; |
|
18
|
|
|
use function AlecRabbit\typeOf; |
|
19
|
|
|
|
|
20
|
|
|
class Factory |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param ReportableInterface $reportable |
|
25
|
|
|
* @return ReportInterface |
|
26
|
|
|
*/ |
|
27
|
|
|
public static function makeReport(ReportableInterface $reportable): ReportInterface |
|
28
|
|
|
{ |
|
29
|
|
|
if ($reportable instanceof Timer) { |
|
30
|
|
|
return |
|
31
|
|
|
new TimerReport($reportable); |
|
32
|
|
|
} |
|
33
|
|
|
if ($reportable instanceof Counter) { |
|
34
|
|
|
return |
|
35
|
|
|
new CounterReport($reportable); |
|
36
|
|
|
} |
|
37
|
|
|
if ($reportable instanceof Profiler) { |
|
38
|
|
|
return |
|
39
|
|
|
new ProfilerReport($reportable); |
|
40
|
|
|
} |
|
41
|
|
|
if ($reportable instanceof Benchmark) { |
|
42
|
|
|
return |
|
43
|
|
|
new BenchmarkReport($reportable); |
|
44
|
|
|
} |
|
45
|
|
|
throw new \RuntimeException('Attempt to create unimplemented report for: ' . typeOf($reportable)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param ReportInterface $report |
|
50
|
|
|
* @return ReportFormatter |
|
51
|
|
|
*/ |
|
52
|
|
|
public static function makeFormatter(ReportInterface $report): ReportFormatter |
|
53
|
|
|
{ |
|
54
|
|
|
// if ($report instanceof TimerReport) { |
|
55
|
|
|
// return |
|
56
|
|
|
// new TimerReportFormatter($report); |
|
57
|
|
|
// } |
|
58
|
|
|
// if ($report instanceof CounterReport) { |
|
59
|
|
|
// return |
|
60
|
|
|
// new CounterReportFormatter($report); |
|
61
|
|
|
// } |
|
62
|
|
|
// if ($report instanceof ProfilerReport) { |
|
63
|
|
|
// return |
|
64
|
|
|
// new ProfilerReportFormatter($report); |
|
65
|
|
|
// } |
|
66
|
|
|
if ($report instanceof BenchmarkReport) { |
|
67
|
|
|
return |
|
68
|
|
|
new BenchmarkReportFormatter($report); |
|
69
|
|
|
} |
|
70
|
|
|
throw new \RuntimeException('Attempt to create unimplemented formatter for: ' . typeOf($report)); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|