Skip to content

Commit a62fa23

Browse files
authored
Merge pull request #25 from MacFJA/fix-paginatedresponse
Fix PaginatedResponse index
2 parents 231129f + b1fc0a2 commit a62fa23

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
- Support from JSON document (require RediSearch 2.2)
1212
- (dev) GitHub Actions
13+
- Protection against division by 0
1314

1415
### Fixed
1516

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

1921
## [2.0.2]
2022

src/Redis/Response/CursorResponse.php

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function getPageSize(): int
106106

107107
public function getPageCount(): int
108108
{
109+
if (0 === $this->size) {
110+
return 0;
111+
}
112+
109113
return (int) ceil($this->totalCount / $this->size);
110114
}
111115

src/Redis/Response/PaginatedResponse.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ public function getPageSize(): int
9696

9797
public function getPageCount(): int
9898
{
99+
if (0 === $this->getPageSize()) {
100+
return 0;
101+
}
102+
99103
return (int) ceil($this->totalCount / $this->getPageSize());
100104
}
101105

@@ -105,7 +109,7 @@ public function key()
105109
return 0;
106110
}
107111

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

111115
public function valid()

0 commit comments

Comments
 (0)