Skip to content

Commit

Permalink
Fixed incorrect logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mazanax committed Feb 26, 2017
1 parent 03c473a commit 8d081ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 8d081ae

Please sign in to comment.