@@ -292,28 +292,28 @@ private static function computeRegexp(array $tokens, int $index, int $firstOptio
292
292
if ('text ' === $ token [0 ]) {
293
293
// Text tokens
294
294
return preg_quote ($ token [1 ]);
295
- } else {
296
- // Variable tokens
297
- if (0 === $ index && 0 === $ firstOptional ) {
298
- // When the only token is an optional variable token, the separator is required
299
- return \sprintf ('%s(?P<%s>%s)? ' , preg_quote ($ token [1 ]), $ token [3 ], $ token [2 ]);
300
- } else {
301
- $ regexp = \sprintf ('%s(?P<%s>%s) ' , preg_quote ($ token [1 ]), $ token [3 ], $ token [2 ]);
302
- if ($ index >= $ firstOptional ) {
303
- // Enclose each optional token in a subpattern to make it optional.
304
- // "?:" means it is non-capturing, i.e. the portion of the subject string that
305
- // matched the optional subpattern is not passed back.
306
- $ regexp = "(?: $ regexp " ;
307
- $ nbTokens = \count ($ tokens );
308
- if ($ nbTokens - 1 == $ index ) {
309
- // Close the optional subpatterns
310
- $ regexp .= str_repeat (')? ' , $ nbTokens - $ firstOptional - (0 === $ firstOptional ? 1 : 0 ));
311
- }
312
- }
295
+ }
313
296
314
- return $ regexp ;
297
+ // Variable tokens
298
+ if (0 === $ index && 0 === $ firstOptional ) {
299
+ // When the only token is an optional variable token, the separator is required
300
+ return \sprintf ('%s(?P<%s>%s)? ' , preg_quote ($ token [1 ]), $ token [3 ], $ token [2 ]);
301
+ }
302
+
303
+ $ regexp = \sprintf ('%s(?P<%s>%s) ' , preg_quote ($ token [1 ]), $ token [3 ], $ token [2 ]);
304
+ if ($ index >= $ firstOptional ) {
305
+ // Enclose each optional token in a subpattern to make it optional.
306
+ // "?:" means it is non-capturing, i.e. the portion of the subject string that
307
+ // matched the optional subpattern is not passed back.
308
+ $ regexp = "(?: $ regexp " ;
309
+ $ nbTokens = \count ($ tokens );
310
+ if ($ nbTokens - 1 == $ index ) {
311
+ // Close the optional subpatterns
312
+ $ regexp .= str_repeat (')? ' , $ nbTokens - $ firstOptional - (0 === $ firstOptional ? 1 : 0 ));
315
313
}
316
314
}
315
+
316
+ return $ regexp ;
317
317
}
318
318
319
319
private static function transformCapturingGroupsToNonCapturings (string $ regexp ): string
0 commit comments