mirror of
https://github.com/shlinkio/shlink.git
synced 2025-03-14 04:00:57 +03:00
Refactored NotFoundRedirectResolver to remove duplicated lines and non-strict code
This commit is contained in:
parent
36e740f4cc
commit
b0a8a03f0a
1 changed files with 12 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue