@@ -147,9 +147,14 @@ public function __construct(
147
147
*/
148
148
public function validate (): ValidationResult
149
149
{
150
+ $ startTime = microtime (true );
151
+
150
152
$ result = new ValidationResult ($ this ->config ->isStrict ());
151
153
$ this ->errorHandler = new ErrorHandler ($ result , $ this ->config ->isDebugEnabled ());
152
154
155
+ // Count main plugin
156
+ $ result ->incrementPluginCount ();
157
+
153
158
// Validate the main plugin
154
159
$ this ->validateSinglePlugin ($ this ->plugin );
155
160
@@ -159,6 +164,12 @@ public function validate(): ValidationResult
159
164
'Validating subplugins '
160
165
);
161
166
167
+ // Record total processing time if debug enabled
168
+ if ($ this ->config ->isDebugEnabled ()) {
169
+ $ totalTime = microtime (true ) - $ startTime ;
170
+ $ result ->setProcessingTime ($ totalTime );
171
+ }
172
+
162
173
return $ result ;
163
174
}
164
175
@@ -181,11 +192,24 @@ private function validateSinglePlugin(Plugin $plugin): void
181
192
$ this ->extractor = new StringExtractor ();
182
193
$ this ->extractor ->setFileDiscovery ($ this ->fileDiscovery );
183
194
195
+ // Track debug information if enabled
196
+ if ($ this ->config ->isDebugEnabled ()) {
197
+ // Collect file discovery metrics
198
+ $ fileMetrics = $ this ->fileDiscovery ->getPerformanceMetrics ();
199
+ $ this ->errorHandler ->getResult ()->addFileCounts ($ fileMetrics ['file_types ' ]);
200
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('file_discovery_ ' . $ plugin ->component , $ fileMetrics ['discovery_time ' ]);
201
+ }
202
+
184
203
// Get defined strings from language file
204
+ $ phaseStart = microtime (true );
185
205
$ definedStrings = $ this ->errorHandler ->safeExecute (
186
206
fn () => $ this ->getDefinedStrings (),
187
207
"Loading language file for {$ plugin ->component }"
188
208
);
209
+ if ($ this ->config ->isDebugEnabled ()) {
210
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('lang_loading_ ' . $ plugin ->component , microtime (true ) - $ phaseStart );
211
+ $ this ->errorHandler ->getResult ()->addStringCounts (['defined_strings ' => count ($ definedStrings )]);
212
+ }
189
213
190
214
// Basic validation - check if language file exists
191
215
if (empty ($ definedStrings )) {
@@ -203,37 +227,66 @@ private function validateSinglePlugin(Plugin $plugin): void
203
227
}
204
228
205
229
// Get plugin-specific requirements
230
+ $ phaseStart = microtime (true );
206
231
$ requirements = $ this ->errorHandler ->safeExecute (
207
232
fn () => $ this ->requirementsResolver ->resolve ($ plugin , $ this ->moodle ->getBranch ()),
208
233
"Resolving plugin requirements for {$ plugin ->component }"
209
234
);
235
+ if ($ this ->config ->isDebugEnabled ()) {
236
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('requirements_resolve_ ' . $ plugin ->component , microtime (true ) - $ phaseStart );
237
+ }
210
238
211
239
if ($ requirements ) {
212
240
// Validate required strings from requirements based on the plugin type.
241
+ $ phaseStart = microtime (true );
213
242
$ this ->errorHandler ->safeExecute (
214
243
fn () => $ this ->validateRequiredStrings ($ requirements ->getRequiredStrings (), $ definedStrings ),
215
244
"Validating required strings for {$ plugin ->component }"
216
245
);
246
+ if ($ this ->config ->isDebugEnabled ()) {
247
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('required_validation_ ' . $ plugin ->component , microtime (true ) - $ phaseStart );
248
+ $ this ->errorHandler ->getResult ()->addStringCounts (['required_strings ' => count ($ requirements ->getRequiredStrings ())]);
249
+ }
217
250
}
218
251
219
252
// Run string checkers for database files and other sources.
253
+ $ phaseStart = microtime (true );
220
254
$ this ->errorHandler ->safeExecute (
221
255
fn () => $ this ->runStringCheckers ($ definedStrings ),
222
256
"Running string checkers for {$ plugin ->component }"
223
257
);
258
+ if ($ this ->config ->isDebugEnabled ()) {
259
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('checkers_ ' . $ plugin ->component , microtime (true ) - $ phaseStart );
260
+ }
224
261
225
262
// Find and validate used strings in the plugin code.
263
+ $ phaseStart = microtime (true );
226
264
$ this ->errorHandler ->safeExecute (
227
265
fn () => $ this ->validateUsedStrings ($ definedStrings ),
228
266
"Validating used strings for {$ plugin ->component }"
229
267
);
268
+ if ($ this ->config ->isDebugEnabled ()) {
269
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('used_validation_ ' . $ plugin ->component , microtime (true ) - $ phaseStart );
270
+
271
+ // Collect string extraction metrics
272
+ $ extractorMetrics = $ this ->extractor ->getPerformanceMetrics ();
273
+ $ this ->errorHandler ->getResult ()->addStringCounts ([
274
+ 'strings_extracted ' => $ extractorMetrics ['strings_extracted ' ],
275
+ 'string_usages_found ' => $ extractorMetrics ['string_usages_found ' ],
276
+ ]);
277
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('string_extraction_ ' . $ plugin ->component , $ extractorMetrics ['extraction_time ' ]);
278
+ }
230
279
231
280
// Check for unused strings if requested.
232
281
if ($ this ->config ->shouldCheckUnused ()) {
282
+ $ phaseStart = microtime (true );
233
283
$ this ->errorHandler ->safeExecute (
234
284
fn () => $ this ->validateUnusedStrings ($ definedStrings , $ requirements ),
235
285
"Checking for unused strings in {$ plugin ->component }"
236
286
);
287
+ if ($ this ->config ->isDebugEnabled ()) {
288
+ $ this ->errorHandler ->getResult ()->addPhaseTime ('unused_validation_ ' . $ plugin ->component , microtime (true ) - $ phaseStart );
289
+ }
237
290
}
238
291
} finally {
239
292
// Restore original plugin and file discovery
@@ -255,6 +308,9 @@ private function validateSubplugins(): void
255
308
}
256
309
257
310
foreach ($ subplugins as $ subplugin ) {
311
+ // Count each subplugin
312
+ $ this ->errorHandler ->getResult ()->incrementSubpluginCount ();
313
+
258
314
$ this ->errorHandler ->safeExecute (
259
315
fn () => $ this ->validateSinglePlugin ($ subplugin ),
260
316
"Validating subplugin {$ subplugin ->component }" ,
0 commit comments