mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Converted visit types into enum
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user