Skip to content

Commit

Permalink
Fix PaginatedResponse index
Browse files Browse the repository at this point in the history
  • Loading branch information
MacFJA committed Jan 15, 2022
1 parent 231129f commit b1fc0a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Support from JSON document (require RediSearch 2.2)
- (dev) GitHub Actions
- Protection against division by 0

### Fixed

- (dev) Code coverage with XDebug 3
- (dev) Defined list of allowed Composer plugins
- Fix `PaginatedResponse` index (now start at 0, and have a linear progression)

## [2.0.2]

Expand Down
4 changes: 4 additions & 0 deletions src/Redis/Response/CursorResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ public function getPageSize(): int

public function getPageCount(): int
{
if (0 === $this->size) {
return 0;
}

return (int) ceil($this->totalCount / $this->size);
}

Expand Down
6 changes: 5 additions & 1 deletion src/Redis/Response/PaginatedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ public function getPageSize(): int

public function getPageCount(): int
{
if (0 === $this->getPageSize()) {
return 0;
}

return (int) ceil($this->totalCount / $this->getPageSize());
}

Expand All @@ -105,7 +109,7 @@ public function key()
return 0;
}

return (int) ceil(($this->lastCommand->getOffset() ?? 0) / $this->getPageSize()) + 1;
return (int) floor(($this->lastCommand->getOffset() ?? 0) / $this->getPageSize());
}

public function valid()
Expand Down

0 comments on commit b1fc0a2

Please sign in to comment.