From deeca582db1d9839ef5cee10e53e1f7df20829ab Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Tue, 10 Nov 2020 17:30:06 +0100 Subject: [PATCH] #867 Small refactoring on NotFoundRedirecthandler --- .../ErrorHandler/NotFoundRedirectHandler.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php index 13615b7d..37557f4d 100644 --- a/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php +++ b/module/Core/src/ErrorHandler/NotFoundRedirectHandler.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Core\ErrorHandler; -use Laminas\Diactoros\Response; +use Laminas\Diactoros\Response\RedirectResponse; use Mezzio\Router\RouteResult; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -12,17 +12,19 @@ use Psr\Http\Message\UriInterface; use Psr\Http\Server\MiddlewareInterface; use Psr\Http\Server\RequestHandlerInterface; use Shlinkio\Shlink\Core\Action\RedirectAction; -use Shlinkio\Shlink\Core\Options\NotFoundRedirectOptions; +use Shlinkio\Shlink\Core\Options; use function rtrim; class NotFoundRedirectHandler implements MiddlewareInterface { - private NotFoundRedirectOptions $redirectOptions; + private Options\NotFoundRedirectOptions $redirectOptions; private string $shlinkBasePath; - public function __construct(NotFoundRedirectOptions $redirectOptions, string $shlinkBasePath) - { + public function __construct( + Options\NotFoundRedirectOptions $redirectOptions, + string $shlinkBasePath + ) { $this->redirectOptions = $redirectOptions; $this->shlinkBasePath = $shlinkBasePath; } @@ -41,11 +43,11 @@ class NotFoundRedirectHandler implements MiddlewareInterface $isBaseUrl = rtrim($uri->getPath(), '/') === $this->shlinkBasePath; if ($isBaseUrl && $this->redirectOptions->hasBaseUrlRedirect()) { - return new Response\RedirectResponse($this->redirectOptions->getBaseUrlRedirect()); + return new RedirectResponse($this->redirectOptions->getBaseUrlRedirect()); } if (!$isBaseUrl && $routeResult->isFailure() && $this->redirectOptions->hasRegular404Redirect()) { - return new Response\RedirectResponse($this->redirectOptions->getRegular404Redirect()); + return new RedirectResponse($this->redirectOptions->getRegular404Redirect()); } if ( @@ -53,7 +55,7 @@ class NotFoundRedirectHandler implements MiddlewareInterface $routeResult->getMatchedRouteName() === RedirectAction::class && $this->redirectOptions->hasInvalidShortUrlRedirect() ) { - return new Response\RedirectResponse($this->redirectOptions->getInvalidShortUrlRedirect()); + return new RedirectResponse($this->redirectOptions->getInvalidShortUrlRedirect()); } return null;