diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index f94fe5992b..4191f423dd 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -8245,11 +8245,6 @@ parameters: count: 1 path: src/Core.php - - - message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" - count: 3 - path: src/Core.php - - message: "#^Cannot access offset string on mixed\\.$#" count: 8 diff --git a/src/Core.php b/src/Core.php index 4f08043ae0..53ad31f51e 100644 --- a/src/Core.php +++ b/src/Core.php @@ -157,37 +157,25 @@ class Core } /** - * Checks given $page against given $allowList and returns true if valid - * it optionally ignores query parameters in $page (script.php?ignored) - * - * @param string $page page to check - * @param mixed[] $allowList allow list to check page against - * @param bool $include whether the page is going to be included + * Checks if the given $page is index.php and returns true if valid. + * It ignores query parameters in $page (script.php?ignored) */ - public static function checkPageValidity(string $page, array $allowList = [], bool $include = false): bool + public static function checkPageValidity(string $page): bool { - if ($allowList === []) { - $allowList = ['index.php']; - } - if ($page === '') { return false; } - if (in_array($page, $allowList)) { + if ($page === 'index.php') { return true; } - if ($include) { - return false; - } - $newPage = mb_substr( $page, 0, (int) mb_strpos($page . '?', '?'), ); - if (in_array($newPage, $allowList)) { + if ($newPage === 'index.php') { return true; } @@ -198,7 +186,7 @@ class Core (int) mb_strpos($newPage . '?', '?'), ); - return in_array($newPage, $allowList); + return $newPage === 'index.php'; } /** diff --git a/tests/classes/CoreTest.php b/tests/classes/CoreTest.php index 0f0a0c7668..c5a2ce6ce7 100644 --- a/tests/classes/CoreTest.php +++ b/tests/classes/CoreTest.php @@ -237,33 +237,29 @@ class CoreTest extends AbstractTestCase /** * Test for Core::checkPageValidity * - * @param string $page Page - * @param string[] $allowList Allow list - * @param bool $include whether the page is going to be included - * @param bool $expected Expected value + * @param string $page Page + * @param bool $expected Expected value */ #[DataProvider('providerTestGotoNowhere')] - public function testGotoNowhere(string $page, array $allowList, bool $include, bool $expected): void + public function testGotoNowhere(string $page, bool $expected): void { - $this->assertSame($expected, Core::checkPageValidity($page, $allowList, $include)); + $this->assertSame($expected, Core::checkPageValidity($page)); } /** * Data provider for testGotoNowhere * - * @return array + * @return array */ public static function providerTestGotoNowhere(): array { return [ - ['', [], false, false], - ['', [], true, false], - ['shell.php', ['index.php'], false, false], - ['shell.php', ['index.php'], true, false], - ['index.php?sql.php&test=true', ['index.php'], false, true], - ['index.php?sql.php&test=true', ['index.php'], true, false], - ['index.php%3Fsql.php%26test%3Dtrue', ['index.php'], false, true], - ['index.php%3Fsql.php%26test%3Dtrue', ['index.php'], true, false], + ['', false], + ['shell.php', false], + ['index.php?sql.php&test=true', true], + ['shell.php?sql.php&test=true', false], + ['index.php%3Fsql.php%26test%3Dtrue', true], + ['shell.php%3Fsql.php%26test%3Dtrue', false], ]; }