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