1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace AlecRabbit\Tools\Reports; |
4
|
|
|
|
5
|
|
|
use AlecRabbit\Tools\Reports\Formatters\BenchmarkFunctionFormatter; |
6
|
|
|
use AlecRabbit\Tools\Reports\Formatters\BenchmarkReportFormatter; |
7
|
|
|
use AlecRabbit\Tools\Reports\Formatters\Contracts\FormatterInterface; |
8
|
|
|
use AlecRabbit\Tools\Reports\Formatters\ExtendedCounterReportFormatter; |
9
|
|
|
use AlecRabbit\Tools\Reports\Formatters\ProfilerReportFormatter; |
10
|
|
|
use AlecRabbit\Tools\Reports\Formatters\SimpleCounterReportFormatter; |
11
|
|
|
use AlecRabbit\Tools\Reports\Formatters\TimerReportFormatter; |
12
|
|
|
use function AlecRabbit\typeOf; |
13
|
|
|
|
14
|
|
|
class Factory |
15
|
|
|
{ |
16
|
|
|
/** @var null|TimerReportFormatter */ |
17
|
|
|
protected static $timerReportFormatter; |
18
|
|
|
|
19
|
|
|
/** @var null|SimpleCounterReportFormatter */ |
20
|
|
|
protected static $simpleCounterReportFormatter; |
21
|
|
|
|
22
|
|
|
/** @var null|ExtendedCounterReportFormatter */ |
23
|
|
|
protected static $extendedCounterReportFormatter; |
24
|
|
|
|
25
|
|
|
/** @var null|ProfilerReportFormatter */ |
26
|
|
|
protected static $profilerReportFormatter; |
27
|
|
|
|
28
|
|
|
/** @var null|BenchmarkReportFormatter */ |
29
|
|
|
protected static $benchmarkReportFormatter; |
30
|
|
|
|
31
|
|
|
/** @var null|BenchmarkFunctionFormatter */ |
32
|
|
|
protected static $benchmarkFunctionFormatter; |
33
|
|
|
|
34
|
|
|
/** @codeCoverageIgnore */ |
35
|
|
|
private function __construct() |
36
|
|
|
{ |
37
|
|
|
// Static class |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return TimerReportFormatter |
42
|
|
|
*/ |
43
|
10 |
|
public static function getTimerReportFormatter(): TimerReportFormatter |
44
|
|
|
{ |
45
|
10 |
|
if (null === static::$timerReportFormatter) { |
46
|
1 |
|
static::$timerReportFormatter = new TimerReportFormatter(); |
47
|
|
|
} |
48
|
|
|
return |
49
|
10 |
|
static::$timerReportFormatter; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param null|TimerReportFormatter $timerReportFormatter |
54
|
|
|
*/ |
55
|
|
|
public static function setTimerReportFormatter(?TimerReportFormatter $timerReportFormatter): void |
56
|
|
|
{ |
57
|
|
|
self::$timerReportFormatter = $timerReportFormatter; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return SimpleCounterReportFormatter |
62
|
|
|
*/ |
63
|
1 |
|
public static function getSimpleCounterReportFormatter(): SimpleCounterReportFormatter |
64
|
|
|
{ |
65
|
1 |
|
if (null === static::$simpleCounterReportFormatter) { |
66
|
1 |
|
static::$simpleCounterReportFormatter = new SimpleCounterReportFormatter(); |
67
|
|
|
} |
68
|
|
|
return |
69
|
1 |
|
new SimpleCounterReportFormatter(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param null|SimpleCounterReportFormatter $simpleCounterReportFormatter |
74
|
|
|
*/ |
75
|
|
|
public static function setSimpleCounterReportFormatter( |
76
|
|
|
?SimpleCounterReportFormatter $simpleCounterReportFormatter |
77
|
|
|
): void { |
78
|
|
|
self::$simpleCounterReportFormatter = $simpleCounterReportFormatter; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return ExtendedCounterReportFormatter |
83
|
|
|
*/ |
84
|
2 |
|
public static function getExtendedCounterReportFormatter(): ExtendedCounterReportFormatter |
85
|
|
|
{ |
86
|
2 |
|
if (null === static::$extendedCounterReportFormatter) { |
87
|
1 |
|
static::$extendedCounterReportFormatter = new ExtendedCounterReportFormatter(); |
88
|
|
|
} |
89
|
|
|
return |
90
|
2 |
|
new ExtendedCounterReportFormatter(); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param null|ExtendedCounterReportFormatter $extendedCounterReportFormatter |
95
|
|
|
*/ |
96
|
|
|
public static function setExtendedCounterReportFormatter( |
97
|
|
|
?ExtendedCounterReportFormatter $extendedCounterReportFormatter |
98
|
|
|
): void { |
99
|
|
|
self::$extendedCounterReportFormatter = $extendedCounterReportFormatter; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return BenchmarkFunctionFormatter |
104
|
|
|
*/ |
105
|
12 |
|
public static function getBenchmarkFunctionFormatter(): BenchmarkFunctionFormatter |
106
|
|
|
{ |
107
|
12 |
|
if (null === static::$benchmarkFunctionFormatter) { |
108
|
1 |
|
static::$benchmarkFunctionFormatter = new BenchmarkFunctionFormatter(); |
109
|
|
|
} |
110
|
|
|
return |
111
|
12 |
|
static::$benchmarkFunctionFormatter->resetEqualReturns(); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param BenchmarkFunctionFormatter $benchmarkFunctionFormatter |
116
|
|
|
*/ |
117
|
|
|
public static function setBenchmarkFunctionFormatter( |
118
|
|
|
BenchmarkFunctionFormatter $benchmarkFunctionFormatter |
119
|
|
|
): void { |
120
|
|
|
self::$benchmarkFunctionFormatter = $benchmarkFunctionFormatter; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return BenchmarkReportFormatter |
125
|
|
|
*/ |
126
|
12 |
|
public static function getBenchmarkReportFormatter(): BenchmarkReportFormatter |
127
|
|
|
{ |
128
|
12 |
|
if (null === static::$benchmarkReportFormatter) { |
129
|
1 |
|
static::$benchmarkReportFormatter = new BenchmarkReportFormatter(); |
130
|
|
|
} |
131
|
|
|
return |
132
|
12 |
|
new BenchmarkReportFormatter(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param null|BenchmarkReportFormatter $benchmarkReportFormatter |
137
|
|
|
*/ |
138
|
|
|
public static function setBenchmarkReportFormatter(?BenchmarkReportFormatter $benchmarkReportFormatter): void |
139
|
|
|
{ |
140
|
|
|
self::$benchmarkReportFormatter = $benchmarkReportFormatter; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return ProfilerReportFormatter |
145
|
|
|
*/ |
146
|
1 |
|
public static function getProfilerReportFormatter(): ProfilerReportFormatter |
147
|
|
|
{ |
148
|
1 |
|
if (null === static::$profilerReportFormatter) { |
149
|
1 |
|
static::$profilerReportFormatter = new ProfilerReportFormatter(); |
150
|
|
|
} |
151
|
|
|
return |
152
|
1 |
|
new ProfilerReportFormatter(); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
/** |
156
|
|
|
* @param null|ProfilerReportFormatter $profilerReportFormatter |
157
|
|
|
*/ |
158
|
|
|
public static function setProfilerReportFormatter(?ProfilerReportFormatter $profilerReportFormatter): void |
159
|
|
|
{ |
160
|
|
|
self::$profilerReportFormatter = $profilerReportFormatter; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function setFormatter(FormatterInterface $formatter): void |
164
|
|
|
{ |
165
|
|
|
if ($formatter instanceof TimerReportFormatter) { |
166
|
|
|
static::setTimerReportFormatter($formatter); |
167
|
|
|
} |
168
|
|
|
if ($formatter instanceof ProfilerReportFormatter) { |
169
|
|
|
static::setProfilerReportFormatter($formatter); |
170
|
|
|
} |
171
|
|
|
throw new \RuntimeException('Formatter [' . typeOf($formatter) .'] is not accepted.'); |
172
|
|
|
} |
173
|
|
|
} |
174
|
|
|
|