Skip to content

Commit

Permalink
Merge pull request #8621 from justbyitself/refactor-1
Browse files Browse the repository at this point in the history
refactor: apply early return pattern
  • Loading branch information
MGatner authored Mar 15, 2024
2 parents 58aa732 + 647d20b commit aeafd03
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions system/Commands/Utilities/Routes/ControllerMethodReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,17 @@ private function getRouteWithoutController(
string $classname,
string $methodName
): array {
$output = [];

if ($classShortname === $defaultController) {
$pattern = '#' . preg_quote(lcfirst($defaultController), '#') . '\z#';
$routeWithoutController = rtrim(preg_replace($pattern, '', $uriByClass), '/');
$routeWithoutController = $routeWithoutController ?: '/';

$output[] = [
'route' => $routeWithoutController,
'handler' => '\\' . $classname . '::' . $methodName,
];
if ($classShortname !== $defaultController) {
return [];
}

return $output;
$pattern = '#' . preg_quote(lcfirst($defaultController), '#') . '\z#';
$routeWithoutController = rtrim(preg_replace($pattern, '', $uriByClass), '/');
$routeWithoutController = $routeWithoutController ?: '/';

return [[
'route' => $routeWithoutController,
'handler' => '\\' . $classname . '::' . $methodName,
]];
}
}

0 comments on commit aeafd03

Please sign in to comment.