Skip to content

Commit a9e44f0

Browse files
committed
refactor: remove uneeded variable and if statement
1 parent ec489c3 commit a9e44f0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

system/Router/RouteCollection.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ public function reverseRoute(string $search, ...$params)
11731173
// If it's not a named route, then loop over
11741174
// all routes to find a match.
11751175
foreach ($this->routes as $collection) {
1176-
foreach ($collection as $routeKey => $route) {
1176+
foreach ($collection as $route) {
11771177
$to = $route['handler'];
11781178
$from = $route['from'];
11791179

@@ -1346,13 +1346,10 @@ protected function buildReverseRoute(string $from, array $params): string
13461346
);
13471347
}
13481348

1349+
// Remove `(:` and `)` when $placeholder is a placeholder.
13491350
$placeholderName = substr($placeholder, 2, -1);
1350-
if (isset($this->placeholders[$placeholderName])) {
1351-
$pattern = $this->placeholders[$placeholderName];
1352-
} else {
1353-
// The $placeholder is not a placeholder. It is a regex.
1354-
$pattern = $placeholder;
1355-
}
1351+
// or maybe $placeholder is not a placeholder, but a regex.
1352+
$pattern = $this->placeholders[$placeholderName] ?? $placeholder;
13561353

13571354
if (! preg_match('#^' . $pattern . '$#u', $params[$index])) {
13581355
throw RouterException::forInvalidParameterType();

0 commit comments

Comments
 (0)