totalPages = $perPage > 0 ? (int) ceil($total / $perPage) : 1; $this->offset = ($page - 1) * $perPage; } public function hasPages(): bool { return $this->totalPages > 1; } public function previousPage(): ?int { return $this->page > 1 ? $this->page - 1 : null; } public function nextPage(): ?int { return $this->page < $this->totalPages ? $this->page + 1 : null; } /** @return list */ public function pageRange(): array { $start = max(1, $this->page - 2); $end = min($this->totalPages, $this->page + 2); return range($start, $end); } }