Skip to content

Commit 1e0025d

Browse files
authored
Merge pull request #166 from Sammyjo20/fix/v2-cursor-paginator-properties
Fix | V2 Fixed cursorPaginator properties
2 parents 50f732c + 4adcd25 commit 1e0025d

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/Http/Paginators/CursorPaginator.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ class CursorPaginator extends Paginator
3636
*
3737
* @var string
3838
*/
39-
protected string $nextPageKey = 'next_page_url';
39+
protected string $nextPageKeyName = 'next_page_url';
4040

4141
/**
4242
* The key/query parameter that contains the cursor
4343
*
4444
* @var string
4545
*/
46-
protected string $cursorKey = 'cursor';
46+
protected string $cursorKeyName = 'cursor';
4747

4848
/**
4949
* Constructor
@@ -99,7 +99,7 @@ protected function applyPagination(Request $request): void
9999
$request->query()->add($this->getLimitKeyName(), $this->limit());
100100
}
101101

102-
$request->query()->add($this->getCursorKey(), $this->currentCursor);
102+
$request->query()->add($this->getCursorKeyName(), $this->currentCursor);
103103
}
104104

105105
/**
@@ -114,7 +114,7 @@ protected function isFinished(): bool
114114
return $this->currentPage > $this->totalPages();
115115
}
116116

117-
return is_null($this->currentResponse->json($this->getNextPageKey()));
117+
return is_null($this->currentResponse->json($this->getNextPageKeyName()));
118118
}
119119

120120
/**
@@ -135,41 +135,41 @@ public function key(): string|int
135135
*/
136136
protected function getCursor(): string|int|null
137137
{
138-
$rawQuery = parse_url($this->currentResponse->json($this->getNextPageKey()) ?? '', PHP_URL_QUERY);
138+
$rawQuery = parse_url($this->currentResponse->json($this->getNextPageKeyName()) ?? '', PHP_URL_QUERY);
139139

140140
if (empty($rawQuery)) {
141141
return null;
142142
}
143143

144144
parse_str($rawQuery, $query);
145145

146-
$cursorValue = $query[$this->getCursorKey()] ?? null;
146+
$cursorValue = $query[$this->getCursorKeyName()] ?? null;
147147

148148
return is_array($cursorValue) ? $cursorValue[0] : $cursorValue;
149149
}
150150

151151
/**
152152
* Set the JSON key for the next page URL that contains the cursor
153153
*
154-
* @param string $nextPageKey
154+
* @param string $nextPageKeyName
155155
* @return $this
156156
*/
157-
public function setNextPageKey(string $nextPageKey): static
157+
public function setNextPageKeyName(string $nextPageKeyName): static
158158
{
159-
$this->nextPageKey = $nextPageKey;
159+
$this->nextPageKeyName = $nextPageKeyName;
160160

161161
return $this;
162162
}
163163

164164
/**
165165
* Set the key/query parameter that contains the cursor
166166
*
167-
* @param string $cursorKey
167+
* @param string $cursorKeyName
168168
* @return $this
169169
*/
170-
public function setCursorKey(string $cursorKey): static
170+
public function setCursorKeyName(string $cursorKeyName): static
171171
{
172-
$this->cursorKey = $cursorKey;
172+
$this->cursorKeyName = $cursorKeyName;
173173

174174
return $this;
175175
}
@@ -179,18 +179,18 @@ public function setCursorKey(string $cursorKey): static
179179
*
180180
* @return string
181181
*/
182-
public function getNextPageKey(): string
182+
public function getNextPageKeyName(): string
183183
{
184-
return $this->nextPageKey;
184+
return $this->nextPageKeyName;
185185
}
186186

187187
/**
188188
* Get the cursor key
189189
*
190190
* @return string
191191
*/
192-
public function getCursorKey(): string
192+
public function getCursorKeyName(): string
193193
{
194-
return $this->cursorKey;
194+
return $this->cursorKeyName;
195195
}
196196
}

tests/Unit/RequestPaginationTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@
328328
$request = new CursorGetSuperHeroesRequest;
329329
$paginator = $connector->paginate($request);
330330

331-
expect($paginator->getNextPageKey())->toEqual('next_page_url');
332-
expect($paginator->getCursorKey())->toEqual('cursor');
331+
expect($paginator->getNextPageKeyName())->toEqual('next_page_url');
332+
expect($paginator->getCursorKeyName())->toEqual('cursor');
333333

334-
$paginator->setNextPageKey('next');
335-
$paginator->setCursorKey('token');
334+
$paginator->setNextPageKeyName('next');
335+
$paginator->setCursorKeyName('token');
336336

337-
expect($paginator->getNextPageKey())->toEqual('next');
338-
expect($paginator->getCursorKey())->toEqual('token');
337+
expect($paginator->getNextPageKeyName())->toEqual('next');
338+
expect($paginator->getCursorKeyName())->toEqual('token');
339339
});

0 commit comments

Comments
 (0)