diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 83a947a76f94..83986e548050 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -8041,21 +8041,11 @@ 'count' => 1, 'path' => __DIR__ . '/system/Pager/Pager.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Only booleans are allowed in an if condition, array given\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Pager/Pager.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Pager\\\\Pager\\:\\:\\$groups type has no value type specified in iterable type array\\.$#', 'count' => 1, 'path' => __DIR__ . '/system/Pager/Pager.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Pager\\\\Pager\\:\\:\\$only type has no value type specified in iterable type array\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Pager/Pager.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\Pager\\\\Pager\\:\\:\\$segment type has no value type specified in iterable type array\\.$#', 'count' => 1, diff --git a/system/Pager/Pager.php b/system/Pager/Pager.php index d9de5faab401..0834fe09f0e4 100644 --- a/system/Pager/Pager.php +++ b/system/Pager/Pager.php @@ -60,9 +60,9 @@ class Pager implements PagerInterface /** * List of only permitted queries * - * @var array + * @var list|null */ - protected $only = []; + protected $only; /** * Constructor. @@ -276,7 +276,7 @@ public function getPageURI(?int $page = null, string $group = 'default', bool $r $uri->addQuery($this->groups[$group]['pageSelector'], $page); } - if ($this->only) { + if ($this->only !== null) { $query = array_intersect_key($_GET, array_flip($this->only)); if (! $segment) { diff --git a/tests/system/Pager/PagerTest.php b/tests/system/Pager/PagerTest.php index f5059f082b53..25c923265f33 100644 --- a/tests/system/Pager/PagerTest.php +++ b/tests/system/Pager/PagerTest.php @@ -165,6 +165,10 @@ public function testStoreWithQueries(): void 'http://example.com/?foo=bar&page=5', $this->pager->only(['foo'])->getPageURI(5) ); + $this->assertSame( + 'http://example.com/?page=5', + $this->pager->only([])->getPageURI(5) + ); } public function testStoreWithSegments(): void @@ -181,6 +185,10 @@ public function testStoreWithSegments(): void 'http://example.com/5?foo=bar', $this->pager->only(['foo'])->getPageURI(5) ); + $this->assertSame( + 'http://example.com/5', + $this->pager->only([])->getPageURI(5) + ); } public function testGetPageURIWithURIReturnObject(): void