diff --git a/src/Paginator.php b/src/Paginator.php index c6f3329..3642aa0 100644 --- a/src/Paginator.php +++ b/src/Paginator.php @@ -51,7 +51,7 @@ public function getPages(int $currentPage, int $itemsCount): array if ($currentPage >= $firstPage + $limit && $currentPage <= $lastPage - $limit) { $commonSection = range($currentPage - $partSize, $currentPage + $partSize); - } elseif ($currentPage <= $firstPage + $limit) { + } elseif ($currentPage < $firstPage + $limit) { $commonSection = range($firstPage, min($firstPage + $limit, $lastPage)); } else { $commonSection = range(max($firstPage, $lastPage - $limit), $lastPage); diff --git a/src/PaginatorTest.php b/src/PaginatorTest.php index 5398210..ee1c886 100644 --- a/src/PaginatorTest.php +++ b/src/PaginatorTest.php @@ -87,5 +87,9 @@ public function testGetPagesWithSeparator() static::assertEquals([1, $separator, 17, 18, 19, 20], $paginator3->getPages(18, 100)); static::assertEquals([1, $separator, 15, 16, 17, 18, 19, 20], $paginator3->getPages(17, 100)); static::assertEquals([1, $separator, 14, 15, 16, 17, 18, $separator, 20], $paginator3->getPages(16, 100)); + + $paginator4 = new Paginator(['on_page' => 1, 'section_size' => 5, 'separator' => $separator]); + + static::assertEquals([1, $separator, 4, 5, 6, 7, 8], $paginator4->getPages(5, 8)); } }