Skip to content

Commit

Permalink
refactor: remove uneeded variable and if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Aug 30, 2023
1 parent ec489c3 commit a9e44f0
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions system/Router/RouteCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ public function reverseRoute(string $search, ...$params)
// If it's not a named route, then loop over
// all routes to find a match.
foreach ($this->routes as $collection) {
foreach ($collection as $routeKey => $route) {
foreach ($collection as $route) {
$to = $route['handler'];
$from = $route['from'];

Expand Down Expand Up @@ -1346,13 +1346,10 @@ protected function buildReverseRoute(string $from, array $params): string
);
}

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

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

0 comments on commit a9e44f0

Please sign in to comment.