Refactored NotFoundRedirectResolver to remove duplicated lines and non-strict code

This commit is contained in:
Alejandro Celaya 2021-10-03 10:35:35 +02:00
parent 36e740f4cc
commit b0a8a03f0a

View file

@ -27,24 +27,21 @@ class NotFoundRedirectResolver implements NotFoundRedirectResolverInterface
NotFoundRedirectConfigInterface $config,
UriInterface $currentUri,
): ?ResponseInterface {
return match (true) {
$notFoundType->isBaseUrl() && $config->hasBaseUrlRedirect() =>
$this->redirectResponseHelper->buildRedirectResponse(
// @phpstan-ignore-next-line Create custom PHPStan rule
$this->resolvePlaceholders($currentUri, $config->baseUrlRedirect()),
),
$notFoundType->isRegularNotFound() && $config->hasRegular404Redirect() =>
$this->redirectResponseHelper->buildRedirectResponse(
// @phpstan-ignore-next-line Create custom PHPStan rule
$this->resolvePlaceholders($currentUri, $config->regular404Redirect()),
),
$urlToRedirectTo = match (true) {
$notFoundType->isBaseUrl() && $config->hasBaseUrlRedirect() => $config->baseUrlRedirect(),
$notFoundType->isRegularNotFound() && $config->hasRegular404Redirect() => $config->regular404Redirect(),
$notFoundType->isInvalidShortUrl() && $config->hasInvalidShortUrlRedirect() =>
$this->redirectResponseHelper->buildRedirectResponse(
// @phpstan-ignore-next-line Create custom PHPStan rule
$this->resolvePlaceholders($currentUri, $config->invalidShortUrlRedirect()),
),
$config->invalidShortUrlRedirect(),
default => null,
};
if ($urlToRedirectTo === null) {
return null;
}
return $this->redirectResponseHelper->buildRedirectResponse(
$this->resolvePlaceholders($currentUri, $urlToRedirectTo),
);
}
private function resolvePlaceholders(UriInterface $currentUri, string $redirectUrl): string