Converted visit types into enum

This commit is contained in:
Alejandro Celaya
2022-04-23 18:19:16 +02:00
parent bca3e62ced
commit 404455928e
10 changed files with 70 additions and 51 deletions

View File

@@ -7,13 +7,13 @@ namespace Shlinkio\Shlink\Core\ErrorHandler\Model;
use Mezzio\Router\RouteResult;
use Psr\Http\Message\ServerRequestInterface;
use Shlinkio\Shlink\Core\Action\RedirectAction;
use Shlinkio\Shlink\Core\Entity\Visit;
use Shlinkio\Shlink\Core\Visit\Model\VisitType;
use function rtrim;
class NotFoundType
{
private function __construct(private string $type)
private function __construct(private readonly VisitType $type)
{
}
@@ -24,10 +24,10 @@ class NotFoundType
$isBaseUrl = rtrim($request->getUri()->getPath(), '/') === $basePath;
$type = match (true) {
$isBaseUrl => Visit::TYPE_BASE_URL,
$routeResult->isFailure() => Visit::TYPE_REGULAR_404,
$routeResult->getMatchedRouteName() === RedirectAction::class => Visit::TYPE_INVALID_SHORT_URL,
default => self::class,
$isBaseUrl => VisitType::BASE_URL,
$routeResult->isFailure() => VisitType::REGULAR_404,
$routeResult->getMatchedRouteName() === RedirectAction::class => VisitType::INVALID_SHORT_URL,
default => VisitType::VALID_SHORT_URL,
};
return new self($type);
@@ -35,16 +35,16 @@ class NotFoundType
public function isBaseUrl(): bool
{
return $this->type === Visit::TYPE_BASE_URL;
return $this->type === VisitType::BASE_URL;
}
public function isRegularNotFound(): bool
{
return $this->type === Visit::TYPE_REGULAR_404;
return $this->type === VisitType::REGULAR_404;
}
public function isInvalidShortUrl(): bool
{
return $this->type === Visit::TYPE_INVALID_SHORT_URL;
return $this->type === VisitType::INVALID_SHORT_URL;
}
}