Skip to content

Commit 289cd96

Browse files
authored
Merge pull request #8702 from kenjis/fix-pager-only-empty
fix: `Pager::only([])` does not work
2 parents 57c0c5a + 22f4c38 commit 289cd96

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7931,21 +7931,11 @@
79317931
'count' => 1,
79327932
'path' => __DIR__ . '/system/Pager/Pager.php',
79337933
];
7934-
$ignoreErrors[] = [
7935-
'message' => '#^Only booleans are allowed in an if condition, array given\\.$#',
7936-
'count' => 1,
7937-
'path' => __DIR__ . '/system/Pager/Pager.php',
7938-
];
79397934
$ignoreErrors[] = [
79407935
'message' => '#^Property CodeIgniter\\\\Pager\\\\Pager\\:\\:\\$groups type has no value type specified in iterable type array\\.$#',
79417936
'count' => 1,
79427937
'path' => __DIR__ . '/system/Pager/Pager.php',
79437938
];
7944-
$ignoreErrors[] = [
7945-
'message' => '#^Property CodeIgniter\\\\Pager\\\\Pager\\:\\:\\$only type has no value type specified in iterable type array\\.$#',
7946-
'count' => 1,
7947-
'path' => __DIR__ . '/system/Pager/Pager.php',
7948-
];
79497939
$ignoreErrors[] = [
79507940
'message' => '#^Property CodeIgniter\\\\Pager\\\\Pager\\:\\:\\$segment type has no value type specified in iterable type array\\.$#',
79517941
'count' => 1,

system/Pager/Pager.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ class Pager implements PagerInterface
6060
/**
6161
* List of only permitted queries
6262
*
63-
* @var array
63+
* @var list<string>|null
6464
*/
65-
protected $only = [];
65+
protected $only;
6666

6767
/**
6868
* Constructor.
@@ -276,7 +276,7 @@ public function getPageURI(?int $page = null, string $group = 'default', bool $r
276276
$uri->addQuery($this->groups[$group]['pageSelector'], $page);
277277
}
278278

279-
if ($this->only) {
279+
if ($this->only !== null) {
280280
$query = array_intersect_key($_GET, array_flip($this->only));
281281

282282
if (! $segment) {

tests/system/Pager/PagerTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ public function testStoreWithQueries(): void
165165
'http://example.com/?foo=bar&page=5',
166166
$this->pager->only(['foo'])->getPageURI(5)
167167
);
168+
$this->assertSame(
169+
'http://example.com/?page=5',
170+
$this->pager->only([])->getPageURI(5)
171+
);
168172
}
169173

170174
public function testStoreWithSegments(): void
@@ -181,6 +185,10 @@ public function testStoreWithSegments(): void
181185
'http://example.com/5?foo=bar',
182186
$this->pager->only(['foo'])->getPageURI(5)
183187
);
188+
$this->assertSame(
189+
'http://example.com/5',
190+
$this->pager->only([])->getPageURI(5)
191+
);
184192
}
185193

186194
public function testGetPageURIWithURIReturnObject(): void

0 commit comments

Comments
 (0)