Skip to content

Commit

Permalink
fix(add-paging-to-result-set): corrected page calculation to include …
Browse files Browse the repository at this point in the history
…position as well
  • Loading branch information
ncosta-ic committed Apr 12, 2024
1 parent fb6b09c commit 3c75a3a
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,13 @@ public function __construct(Traversable $traversable, $limit = null, $offset = n
public function getCurrentPage(): int
{
if ($this->pageSize) {
if ($this->offset && $this->offset > $this->pageSize) {
// offset is not on the first page anymore
return intval(floor($this->offset / $this->pageSize));
$offset = $this->offset ?: 0;
if ($this->position && ($this->position + $offset) > $this->pageSize) {
// we are not on the first page anymore, calculating proper page
return intval(floor(($this->position + $offset) / $this->pageSize));
}

// no offset defined or still on page 1
// still on the first page
return 1;
}

Expand Down

0 comments on commit 3c75a3a

Please sign in to comment.