Skip to content

Commit

Permalink
Rename internal methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Aug 5, 2023
1 parent 5153ae2 commit ea17634
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ public function handleRequest(Request $request): Response
return $this->fallback->handleRequest($request);
}

return $this->makeNotFoundResponse($request);
return $this->notFound($request);

case Dispatcher::METHOD_NOT_ALLOWED:
return $this->makeMethodNotAllowedResponse($match[1], $request);
return $this->methodNotAllowed($match[1], $request);

default:
// @codeCoverageIgnoreStart
Expand All @@ -104,26 +104,6 @@ public function handleRequest(Request $request): Response
}
}

/**
* Create a response if no routes matched and no fallback has been set.
*/
private function makeNotFoundResponse(Request $request): Response
{
return $this->errorHandler->handleError(HttpStatus::NOT_FOUND, null, $request);
}

/**
* Create a response if the requested method is not allowed for the matched path.
*
* @param string[] $methods
*/
private function makeMethodNotAllowedResponse(array $methods, Request $request): Response
{
$response = $this->errorHandler->handleError(HttpStatus::METHOD_NOT_ALLOWED, null, $request);
$response->setHeader("allow", \implode(", ", $methods));
return $response;
}

/**
* Merge another router's routes into this router.
*
Expand Down Expand Up @@ -242,6 +222,26 @@ public function setFallback(RequestHandler $requestHandler): void
$this->fallback = $requestHandler;
}

/**
* Create a response if no routes matched and no fallback has been set.
*/
private function notFound(Request $request): Response
{
return $this->errorHandler->handleError(HttpStatus::NOT_FOUND, null, $request);
}

/**
* Create a response if the requested method is not allowed for the matched path.
*
* @param string[] $methods
*/
private function methodNotAllowed(array $methods, Request $request): Response
{
$response = $this->errorHandler->handleError(HttpStatus::METHOD_NOT_ALLOWED, null, $request);
$response->setHeader("allow", \implode(", ", $methods));
return $response;
}

private function onStart(): void
{
if ($this->running) {
Expand Down

0 comments on commit ea17634

Please sign in to comment.