From 12123eaedec762e8bfdc05e5380bb6ea2f531cc0 Mon Sep 17 00:00:00 2001 From: Vitor Mattos Date: Thu, 31 Oct 2024 19:48:08 -0300 Subject: [PATCH] refactor: make more readdable Signed-off-by: Vitor Mattos --- lib/Helper/Pagination.php | 48 +++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/lib/Helper/Pagination.php b/lib/Helper/Pagination.php index 1999e82ba3..8ce906b75d 100644 --- a/lib/Helper/Pagination.php +++ b/lib/Helper/Pagination.php @@ -33,29 +33,33 @@ public function setRouteName(string $routeName = ''): self { public function getPagination(?int $page, ?int $length, array $filter = []): array { $this->setMaxPerPage($length); - $pagination['total'] = $this->count(); - if ($pagination['total'] > $length) { - $pagination['current'] = $this->linkToRoute($page, $length, $filter); - $pagination['next'] = $this->hasNextPage() - ? $this->linkToRoute($this->getNextPage(), $length, $filter) - : null; - $pagination['prev'] = $this->hasPreviousPage() - ? $this->linkToRoute($this->getPreviousPage(), $length, $filter) - : null; - $pagination['last'] = $this->hasNextPage() - ? $this->linkToRoute($this->getNbPages(), $length, $filter) - : null; - $pagination['first'] = $this->hasPreviousPage() - ? $this->linkToRoute(1, $length, $filter) - : null; - } else { - $pagination['current'] = null; - $pagination['next'] = null; - $pagination['prev'] = null; - $pagination['last'] = null; - $pagination['first'] = null; + $total = $this->count(); + if ($total > $length) { + return [ + 'total' => $total, + 'current' => $this->linkToRoute($page, $length, $filter), + 'next' => $this->hasNextPage() + ? $this->linkToRoute($this->getNextPage(), $length, $filter) + : null, + 'prev' => $this->hasPreviousPage() + ? $this->linkToRoute($this->getPreviousPage(), $length, $filter) + : null, + 'last' => $this->hasNextPage() + ? $this->linkToRoute($this->getNbPages(), $length, $filter) + : null, + 'first' => $this->hasPreviousPage() + ? $this->linkToRoute(1, $length, $filter) + : null, + ]; } - return $pagination; + return [ + 'total' => $total, + 'current' => null, + 'next' => null, + 'prev' => null, + 'last' => null, + 'first' => null, + ]; } private function linkToRoute(int $page, int $length, array $filter): string {