Skip to content

Commit

Permalink
refactor: rename method and variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Apr 10, 2023
1 parent 9ede977 commit a0578b3
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ public function read(string $class, string $defaultController = 'Home', string $
// Remove HTTP verb prefix.
$methodInUri = lcfirst(substr($methodName, strlen($httpVerb)));

// Check if it is the default method.
if ($methodInUri === $defaultMethod) {
$routeWithoutController = $this->getRouteWithoutController(
$routeForDefaultController = $this->getRouteForDefaultController(
$classShortname,
$defaultController,
$classInUri,
Expand All @@ -75,8 +76,11 @@ public function read(string $class, string $defaultController = 'Home', string $
$httpVerb
);

if ($routeWithoutController !== []) {
$output = [...$output, ...$routeWithoutController];
if ($routeForDefaultController !== []) {
// The controller is the default controller. It only
// has a route for the default method. Other methods
// will be routed even if they exist.
$output = [...$output, ...$routeForDefaultController];

continue;
}
Expand All @@ -93,7 +97,7 @@ public function read(string $class, string $defaultController = 'Home', string $
continue;
}

// Skip the default controller.
// If it is the default controller, no more routes exists.
if ($classShortname === $defaultController) {
continue;
}
Expand Down Expand Up @@ -156,9 +160,9 @@ private function getUriByClass(string $classname): string
}

/**
* Gets a route without default controller.
* Gets a route for the default controller.
*/
private function getRouteWithoutController(
private function getRouteForDefaultController(
string $classShortname,
string $defaultController,
string $uriByClass,
Expand Down

0 comments on commit a0578b3

Please sign in to comment.