@@ -37,10 +37,11 @@ public function __construct(private readonly bool $debug = false)
37
37
public function __destruct ()
38
38
{
39
39
$ this ->console ->newline ();
40
- $ this ->console ->info (sprintf ('HydeStan has exited after scanning %s total (and %s aggregate) lines in %s files. ' ,
40
+ $ this ->console ->info (sprintf ('HydeStan has exited after scanning %s total (and %s aggregate) lines in %s files. Total expressions analysed: %s ' ,
41
41
number_format ($ this ->scannedLines ),
42
42
number_format ($ this ->aggregateLines ),
43
- number_format (count ($ this ->files ))
43
+ number_format (count ($ this ->files )),
44
+ number_format (AnalysisStatisticsContainer::getExpressionsAnalysed ()),
44
45
));
45
46
46
47
if (count (self ::$ warnings ) > 0 ) {
@@ -124,13 +125,15 @@ private function analyseFile(string $file, string $contents): void
124
125
}
125
126
126
127
$ analyser ->run ($ file , $ contents );
128
+ AnalysisStatisticsContainer::countedLines (substr_count ($ contents , "\n" ));
127
129
128
130
foreach (explode ("\n" , $ contents ) as $ lineNumber => $ line ) {
129
131
$ lineAnalysers = [
130
132
new NoTestReferenceAnalyser ($ file , $ lineNumber , $ line ),
131
133
];
132
134
133
135
foreach ($ lineAnalysers as $ analyser ) {
136
+ AnalysisStatisticsContainer::countedLine ();
134
137
$ analyser ->run ($ file , $ lineNumber , $ line );
135
138
$ this ->aggregateLines ++;
136
139
}
@@ -196,6 +199,7 @@ public function run(string $file, string $contents): void
196
199
$ contents = strtolower ($ contents );
197
200
198
201
foreach ($ searches as $ search ) {
202
+ AnalysisStatisticsContainer::analysedExpression ();
199
203
if (str_contains ($ contents , $ search )) {
200
204
// Get line number of marker by counting new \n tags before it
201
205
$ stringBeforeMarker = substr ($ contents , 0 , strpos ($ contents , $ search ));
@@ -219,6 +223,7 @@ public function run(string $file, string $contents): void
219
223
220
224
$ functionImports = [];
221
225
foreach ($ lines as $ line ) {
226
+ AnalysisStatisticsContainer::analysedExpression ();
222
227
if (str_starts_with ($ line , 'use function ' )) {
223
228
$ functionImports [] = rtrim (substr ($ line , 13 ), '; ' );
224
229
}
@@ -228,8 +233,10 @@ public function run(string $file, string $contents): void
228
233
foreach ($ lines as $ line ) {
229
234
// Find all function calls
230
235
preg_match_all ('/([a-zA-Z0-9_]+)\(/ ' , $ line , $ matches );
236
+ AnalysisStatisticsContainer::analysedExpressions (count ($ matches [1 ]));
231
237
232
238
foreach ($ matches [1 ] as $ match ) {
239
+ AnalysisStatisticsContainer::analysedExpression ();
233
240
if (! str_contains ($ line , '-> ' )) {
234
241
$ calledFunctions [] = $ match ;
235
242
}
@@ -241,6 +248,7 @@ public function run(string $file, string $contents): void
241
248
$ calledFunctions = array_unique ($ calledFunctions );
242
249
243
250
foreach ($ calledFunctions as $ calledFunction ) {
251
+ AnalysisStatisticsContainer::analysedExpression ();
244
252
if (! in_array ($ calledFunction , $ functionImports )) {
245
253
echo ("Found unimported function ' $ calledFunction' in " .realpath (__DIR__ .'/../../packages/framework/ ' .$ file ))."\n" ;
246
254
}
@@ -252,13 +260,52 @@ class NoTestReferenceAnalyser extends LineAnalyser
252
260
{
253
261
public function run (string $ file , int $ lineNumber , string $ line ): void
254
262
{
263
+ AnalysisStatisticsContainer::analysedExpressions (1 );
264
+
255
265
if (str_starts_with ($ line , ' * @see ' ) && str_ends_with ($ line , 'Test ' )) {
266
+ AnalysisStatisticsContainer::analysedExpressions (1 );
256
267
$ this ->fail (sprintf ('Test class %s is referenced in %s:%s ' , trim (substr ($ line , 7 )),
257
268
realpath (__DIR__ .'/../../packages/framework/ ' .$ file ) ?: $ file , $ lineNumber + 1 ));
258
269
}
259
270
}
260
271
}
261
272
273
+ class AnalysisStatisticsContainer
274
+ {
275
+ private static int $ linesCounted = 0 ;
276
+ private static float $ expressionsAnalysed = 0 ;
277
+
278
+ public static function countedLine (): void
279
+ {
280
+ self ::$ linesCounted ++;
281
+ }
282
+
283
+ public static function countedLines (int $ count ): void
284
+ {
285
+ self ::$ linesCounted += $ count ;
286
+ }
287
+
288
+ public static function analysedExpression (): void
289
+ {
290
+ self ::$ expressionsAnalysed ++;
291
+ }
292
+
293
+ public static function analysedExpressions (float $ countOrEstimate ): void
294
+ {
295
+ self ::$ expressionsAnalysed += $ countOrEstimate ;
296
+ }
297
+
298
+ public static function getLinesCounted (): int
299
+ {
300
+ return self ::$ linesCounted ;
301
+ }
302
+
303
+ public static function getExpressionsAnalysed (): int
304
+ {
305
+ return (int ) round (self ::$ expressionsAnalysed );
306
+ }
307
+ }
308
+
262
309
interface FileAnalyserContract
263
310
{
264
311
public function __construct (string $ file , string $ contents );
0 commit comments