mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 23:33:13 +08:00
Ensure visits lists where the page is lower than 1, fall back to page 1 to avoid errors
This commit is contained in:
@@ -15,11 +15,11 @@ final class ShortUrlsParams
|
||||
public const DEFAULT_ITEMS_PER_PAGE = 10;
|
||||
|
||||
private int $page;
|
||||
private ?int $itemsPerPage = null;
|
||||
private ?string $searchTerm;
|
||||
private array $tags;
|
||||
private ShortUrlsOrdering $orderBy;
|
||||
private ?DateRange $dateRange;
|
||||
private ?int $itemsPerPage = null;
|
||||
|
||||
private function __construct()
|
||||
{
|
||||
|
||||
@@ -25,11 +25,16 @@ final class VisitsParams
|
||||
bool $excludeBots = false
|
||||
) {
|
||||
$this->dateRange = $dateRange ?? new DateRange();
|
||||
$this->page = $page;
|
||||
$this->page = $this->determinePage($page);
|
||||
$this->itemsPerPage = $this->determineItemsPerPage($itemsPerPage);
|
||||
$this->excludeBots = $excludeBots;
|
||||
}
|
||||
|
||||
private function determinePage(int $page): int
|
||||
{
|
||||
return $page > 0 ? $page : self::FIRST_PAGE;
|
||||
}
|
||||
|
||||
private function determineItemsPerPage(?int $itemsPerPage): int
|
||||
{
|
||||
if ($itemsPerPage !== null && $itemsPerPage < 0) {
|
||||
@@ -43,7 +48,7 @@ final class VisitsParams
|
||||
{
|
||||
return new self(
|
||||
parseDateRangeFromQuery($query, 'startDate', 'endDate'),
|
||||
(int) ($query['page'] ?? 1),
|
||||
(int) ($query['page'] ?? self::FIRST_PAGE),
|
||||
isset($query['itemsPerPage']) ? (int) $query['itemsPerPage'] : null,
|
||||
isset($query['excludeBots']),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user