Skip to content

Commit da97931

Browse files
committed
minor #57897 Remove unused code and unnecessary else branches (alexandre-daubois)
This PR was merged into the 7.2 branch. Discussion ---------- Remove unused code and unnecessary `else` branches | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT - Remove useless `continue` and `return` statements - Replace useless double quotes - Remove unnecessary local variables - Prefer simpler control structures without `else` where possible Commits ------- 1203390e4c Remove unused code and unnecessary `else` branches
2 parents f9a4470 + f84acde commit da97931

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

RouteCompiler.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -292,28 +292,28 @@ private static function computeRegexp(array $tokens, int $index, int $firstOptio
292292
if ('text' === $token[0]) {
293293
// Text tokens
294294
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+
}
313296

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));
315313
}
316314
}
315+
316+
return $regexp;
317317
}
318318

319319
private static function transformCapturingGroupsToNonCapturings(string $regexp): string

0 commit comments

Comments
 (0)