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\ExtendedCounterReportFormatter; |
8
|
|
|
use AlecRabbit\Tools\Reports\Formatters\Formatter; |
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
|
8 |
|
public static function setFormatter(Formatter $formatter): Formatter |
41
|
|
|
{ |
42
|
8 |
|
if ($formatter instanceof SimpleCounterReportFormatter) { |
43
|
1 |
|
static::setSimpleCounterReportFormatter($formatter); |
44
|
1 |
|
return self::getSimpleCounterReportFormatter(); |
45
|
|
|
} |
46
|
7 |
|
if ($formatter instanceof ExtendedCounterReportFormatter) { |
47
|
1 |
|
static::setExtendedCounterReportFormatter($formatter); |
48
|
1 |
|
return self::getExtendedCounterReportFormatter(); |
49
|
|
|
} |
50
|
6 |
|
if ($formatter instanceof TimerReportFormatter) { |
51
|
1 |
|
static::setTimerReportFormatter($formatter); |
52
|
1 |
|
return self::getTimerReportFormatter(); |
53
|
|
|
} |
54
|
5 |
|
if ($formatter instanceof ProfilerReportFormatter) { |
55
|
1 |
|
static::setProfilerReportFormatter($formatter); |
56
|
1 |
|
return self::getProfilerReportFormatter(); |
57
|
|
|
} |
58
|
4 |
|
if ($formatter instanceof BenchmarkReportFormatter) { |
59
|
2 |
|
static::setBenchmarkReportFormatter($formatter); |
60
|
2 |
|
return self::getBenchmarkReportFormatter(); |
61
|
|
|
} |
62
|
2 |
|
if ($formatter instanceof BenchmarkFunctionFormatter) { |
63
|
1 |
|
static::setBenchmarkFunctionFormatter($formatter); |
64
|
1 |
|
return self::getBenchmarkFunctionFormatter(); |
65
|
|
|
} |
66
|
1 |
|
throw new \RuntimeException('Formatter [' . typeOf($formatter) . '] is not accepted.'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return SimpleCounterReportFormatter |
71
|
|
|
*/ |
72
|
6 |
|
public static function getSimpleCounterReportFormatter(): SimpleCounterReportFormatter |
73
|
|
|
{ |
74
|
6 |
|
if (null === static::$simpleCounterReportFormatter) { |
75
|
1 |
|
static::$simpleCounterReportFormatter = new SimpleCounterReportFormatter(); |
76
|
|
|
} |
77
|
|
|
return |
78
|
6 |
|
static::$simpleCounterReportFormatter; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param null|SimpleCounterReportFormatter $simpleCounterReportFormatter |
83
|
|
|
*/ |
84
|
2 |
|
public static function setSimpleCounterReportFormatter( |
85
|
|
|
?SimpleCounterReportFormatter $simpleCounterReportFormatter |
86
|
|
|
): void { |
87
|
2 |
|
static::$simpleCounterReportFormatter = $simpleCounterReportFormatter; |
88
|
2 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return ExtendedCounterReportFormatter |
92
|
|
|
*/ |
93
|
5 |
|
public static function getExtendedCounterReportFormatter(): ExtendedCounterReportFormatter |
94
|
|
|
{ |
95
|
5 |
|
if (null === static::$extendedCounterReportFormatter) { |
96
|
1 |
|
static::$extendedCounterReportFormatter = new ExtendedCounterReportFormatter(); |
97
|
|
|
} |
98
|
|
|
return |
99
|
5 |
|
static::$extendedCounterReportFormatter; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param null|ExtendedCounterReportFormatter $extendedCounterReportFormatter |
104
|
|
|
*/ |
105
|
2 |
|
public static function setExtendedCounterReportFormatter( |
106
|
|
|
?ExtendedCounterReportFormatter $extendedCounterReportFormatter |
107
|
|
|
): void { |
108
|
2 |
|
static::$extendedCounterReportFormatter = $extendedCounterReportFormatter; |
109
|
2 |
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @return TimerReportFormatter |
113
|
|
|
*/ |
114
|
15 |
|
public static function getTimerReportFormatter(): TimerReportFormatter |
115
|
|
|
{ |
116
|
15 |
|
if (null === static::$timerReportFormatter) { |
117
|
1 |
|
static::$timerReportFormatter = new TimerReportFormatter(); |
118
|
|
|
} |
119
|
|
|
return |
120
|
15 |
|
static::$timerReportFormatter; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @param null|TimerReportFormatter $timerReportFormatter |
125
|
|
|
*/ |
126
|
2 |
|
public static function setTimerReportFormatter(?TimerReportFormatter $timerReportFormatter): void |
127
|
|
|
{ |
128
|
2 |
|
static::$timerReportFormatter = $timerReportFormatter; |
129
|
2 |
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @return ProfilerReportFormatter |
133
|
|
|
*/ |
134
|
4 |
|
public static function getProfilerReportFormatter(): ProfilerReportFormatter |
135
|
|
|
{ |
136
|
4 |
|
if (null === static::$profilerReportFormatter) { |
137
|
1 |
|
static::$profilerReportFormatter = new ProfilerReportFormatter(); |
138
|
|
|
} |
139
|
|
|
return |
140
|
4 |
|
static::$profilerReportFormatter; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param null|ProfilerReportFormatter $profilerReportFormatter |
145
|
|
|
*/ |
146
|
2 |
|
public static function setProfilerReportFormatter( |
147
|
|
|
?ProfilerReportFormatter $profilerReportFormatter |
148
|
|
|
): void { |
149
|
2 |
|
static::$profilerReportFormatter = $profilerReportFormatter; |
150
|
2 |
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @return BenchmarkReportFormatter |
154
|
|
|
*/ |
155
|
12 |
|
public static function getBenchmarkReportFormatter(): BenchmarkReportFormatter |
156
|
|
|
{ |
157
|
12 |
|
if (null === static::$benchmarkReportFormatter) { |
158
|
1 |
|
static::$benchmarkReportFormatter = new BenchmarkReportFormatter(); |
159
|
|
|
} |
160
|
|
|
return |
161
|
12 |
|
static::$benchmarkReportFormatter; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param null|BenchmarkReportFormatter $benchmarkReportFormatter |
166
|
|
|
*/ |
167
|
3 |
|
public static function setBenchmarkReportFormatter( |
168
|
|
|
?BenchmarkReportFormatter $benchmarkReportFormatter |
169
|
|
|
): void { |
170
|
3 |
|
static::$benchmarkReportFormatter = $benchmarkReportFormatter; |
171
|
3 |
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @return BenchmarkFunctionFormatter |
175
|
|
|
*/ |
176
|
11 |
|
public static function getBenchmarkFunctionFormatter(): BenchmarkFunctionFormatter |
177
|
|
|
{ |
178
|
11 |
|
if (null === static::$benchmarkFunctionFormatter) { |
179
|
1 |
|
static::$benchmarkFunctionFormatter = new BenchmarkFunctionFormatter(); |
180
|
|
|
} |
181
|
|
|
return |
182
|
11 |
|
static::$benchmarkFunctionFormatter->resetEqualReturns(); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param null|BenchmarkFunctionFormatter $benchmarkFunctionFormatter |
187
|
|
|
*/ |
188
|
2 |
|
public static function setBenchmarkFunctionFormatter( |
189
|
|
|
?BenchmarkFunctionFormatter $benchmarkFunctionFormatter |
190
|
|
|
): void { |
191
|
2 |
|
static::$benchmarkFunctionFormatter = $benchmarkFunctionFormatter; |
192
|
2 |
|
} |
193
|
|
|
} |
194
|
|
|
|