diff --git a/.gitattributes b/.gitattributes index b1d0822c10d5..05fc1f38cde9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,7 +26,7 @@ structarmed.php export-ignore phpmetrics.json export-ignore phpstan-baseline.php export-ignore phpstan-bootstrap.php export-ignore -phpstan.neon.dist export-ignore +phpstan.dist.neon export-ignore phpunit.dist.xml export-ignore psalm-baseline.xml export-ignore psalm.xml export-ignore diff --git a/.github/workflows/test-phpstan.yml b/.github/workflows/test-phpstan.yml index 6c1461cb3318..fbae39d8608b 100644 --- a/.github/workflows/test-phpstan.yml +++ b/.github/workflows/test-phpstan.yml @@ -13,7 +13,7 @@ on: - 'tests/**.php' - 'utils/**.php' - composer.json - - phpstan.neon.dist + - phpstan.dist.neon - phpstan-baseline.php - '.github/workflows/test-phpstan.yml' @@ -27,7 +27,7 @@ on: - 'tests/**.php' - 'utils/**.php' - composer.json - - phpstan.neon.dist + - phpstan.dist.neon - phpstan-baseline.php - '.github/workflows/test-phpstan.yml' diff --git a/composer.json b/composer.json index 3d257784b2f0..b3a5a6d513ea 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ }, "require-dev": { "boundwize/structarmed": "0.13.4", - "codeigniter/phpstan-codeigniter": "^1.5", + "codeigniter/phpstan-codeigniter": "^2.1", "fakerphp/faker": "^1.24", "kint-php/kint": "^6.1", "mikey179/vfsstream": "^1.6.12", diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php index 0f45bf0cb559..ef64b6c23a52 100644 --- a/phpstan-bootstrap.php +++ b/phpstan-bootstrap.php @@ -1,5 +1,9 @@ withPHPStanConfigs([ - __DIR__ . '/phpstan.neon.dist', + __DIR__ . '/phpstan.dist.neon', __DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon', __DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon', __DIR__ . '/vendor/shipmonk/phpstan-baseline-per-identifier/extension.neon', diff --git a/system/BaseModel.php b/system/BaseModel.php index d40a662724d9..6f52c02a48c6 100644 --- a/system/BaseModel.php +++ b/system/BaseModel.php @@ -49,7 +49,7 @@ * - process various callbacks * - allow intermingling calls to the db connection * - * @phpstan-type row_array array + * @phpstan-type row_array array * @phpstan-type event_data_beforeinsert array{data: row_array} * @phpstan-type event_data_afterinsert array{id: int|string, data: row_array, result: bool} * @phpstan-type event_data_beforefind array{id?: int|string, method: string, singleton: bool, limit?: int, offset?: int} diff --git a/system/Boot.php b/system/Boot.php index d3b25895093b..dccd85a03b52 100644 --- a/system/Boot.php +++ b/system/Boot.php @@ -426,9 +426,11 @@ protected static function initializeConsole(): Console { $console = new Console(); + $args = service('superglobals')->server('argv', []); + // Show basic information before we do anything else. - if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) { - unset($_SERVER['argv'][$suppress]); + if (is_int($suppress = array_search('--no-header', $args, true))) { + unset($args[$suppress]); $suppress = true; } diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index 9cdbbbada0b5..9a1d8afba963 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -707,7 +707,9 @@ public static function streamSupports(string $function, $resource): bool public static function hasColorSupport($resource): bool { // Follow https://no-color.org/ - if (isset($_SERVER['NO_COLOR']) || getenv('NO_COLOR') !== false) { + $noColor = service('superglobals')->server('NO_COLOR'); + + if (isset($noColor) || getenv('NO_COLOR') !== false) { return false; } @@ -716,9 +718,11 @@ public static function hasColorSupport($resource): bool } if (is_windows()) { + $ansicon = service('superglobals')->server('ANSICON'); + // @codeCoverageIgnoreStart return static::streamSupports('sapi_windows_vt100_support', $resource) - || isset($_SERVER['ANSICON']) + || isset($ansicon) || getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON' || getenv('TERM') === 'xterm'; @@ -887,7 +891,7 @@ public static function wrap(?string $string = null, int $max = 0, int $padLeft = */ protected static function parseCommandLine() { - $args = $_SERVER['argv'] ?? []; + $args = service('superglobals')->server('argv') ?? []; array_shift($args); // scrap invoking program $optionValue = false; diff --git a/system/Commands/Encryption/GenerateKey.php b/system/Commands/Encryption/GenerateKey.php index 3726360fa8ad..148fd264dc33 100644 --- a/system/Commands/Encryption/GenerateKey.php +++ b/system/Commands/Encryption/GenerateKey.php @@ -101,7 +101,8 @@ public function run(array $params) // force DotEnv to reload the new env vars putenv('encryption.key'); - unset($_ENV['encryption.key'], $_SERVER['encryption.key']); + unset($_ENV['encryption.key']); + service('superglobals')->unsetServer('encryption.key'); $dotenv = new DotEnv((new Paths())->envDirectory ?? ROOTPATH); // @phpstan-ignore nullCoalesce.property $dotenv->load(); diff --git a/system/Common.php b/system/Common.php index f3f20a7a0db5..5b64412c4af7 100644 --- a/system/Common.php +++ b/system/Common.php @@ -409,7 +409,7 @@ function db_connect($db = null, bool $getShared = true) */ function env(string $key, $default = null) { - $value = $_ENV[$key] ?? $_SERVER[$key] ?? getenv($key); + $value = $_ENV[$key] ?? service('superglobals')->server($key) ?? getenv($key); // Not found? Return the default value if ($value === false) { @@ -695,9 +695,11 @@ function is_cli(): bool return true; } + $superglobals = service('superglobals'); + // PHP_SAPI could be 'cgi-fcgi', 'fpm-fcgi'. // See https://github.com/codeigniter4/CodeIgniter4/pull/5393 - return ! isset($_SERVER['REMOTE_ADDR']) && ! isset($_SERVER['REQUEST_METHOD']); + return $superglobals->server('REMOTE_ADDR') === null && $superglobals->server('REQUEST_METHOD') === null; } } diff --git a/system/Config/AutoloadConfig.php b/system/Config/AutoloadConfig.php index b6d7f72bdd54..f35df4ebe740 100644 --- a/system/Config/AutoloadConfig.php +++ b/system/Config/AutoloadConfig.php @@ -142,7 +142,8 @@ class AutoloadConfig */ public function __construct() { - if (isset($_SERVER['CI_ENVIRONMENT']) && $_SERVER['CI_ENVIRONMENT'] === 'testing') { + // @phpstan-ignore codeigniter.superglobalsOffsetAccess (service() is not yet available) + if (($_SERVER['CI_ENVIRONMENT'] ?? null) === 'testing') { $this->psr4['Tests\Support'] = SUPPORTPATH; $this->classmap['CodeIgniter\Log\TestLogger'] = SYSTEMPATH . 'Test/TestLogger.php'; $this->classmap['CIDatabaseTestCase'] = SYSTEMPATH . 'Test/CIDatabaseTestCase.php'; diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index 42da45cdb52f..6b35d078ea74 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -221,10 +221,10 @@ protected function getEnvValue(string $property, string $prefix, string $shortPr return $_ENV["{$shortPrefix}_{$underscoreProperty}"]; case array_key_exists("{$shortPrefix}.{$property}", $_SERVER): - return $_SERVER["{$shortPrefix}.{$property}"]; + return $_SERVER["{$shortPrefix}.{$property}"]; // @phpstan-ignore codeigniter.superglobalsOffsetAccess case array_key_exists("{$shortPrefix}_{$underscoreProperty}", $_SERVER): - return $_SERVER["{$shortPrefix}_{$underscoreProperty}"]; + return $_SERVER["{$shortPrefix}_{$underscoreProperty}"]; // @phpstan-ignore codeigniter.superglobalsOffsetAccess case array_key_exists("{$prefix}.{$property}", $_ENV): return $_ENV["{$prefix}.{$property}"]; @@ -233,10 +233,10 @@ protected function getEnvValue(string $property, string $prefix, string $shortPr return $_ENV["{$prefix}_{$underscoreProperty}"]; case array_key_exists("{$prefix}.{$property}", $_SERVER): - return $_SERVER["{$prefix}.{$property}"]; + return $_SERVER["{$prefix}.{$property}"]; // @phpstan-ignore codeigniter.superglobalsOffsetAccess case array_key_exists("{$prefix}_{$underscoreProperty}", $_SERVER): - return $_SERVER["{$prefix}_{$underscoreProperty}"]; + return $_SERVER["{$prefix}_{$underscoreProperty}"]; // @phpstan-ignore codeigniter.superglobalsOffsetAccess default: $value = getenv("{$shortPrefix}.{$property}"); diff --git a/system/Filters/Filters.php b/system/Filters/Filters.php index 5ec5fc0fa074..bf5419eab560 100644 --- a/system/Filters/Filters.php +++ b/system/Filters/Filters.php @@ -375,7 +375,7 @@ public function getRequiredFilters(string $position = 'before'): array { // For backward compatibility. For users who do not update Config\Filters. if (! isset($this->config->required[$position])) { - $baseConfig = config(BaseFiltersConfig::class); // @phpstan-ignore-line + $baseConfig = config(BaseFiltersConfig::class); $filters = $baseConfig->required[$position]; $aliases = $baseConfig->aliases; } else { diff --git a/system/Session/Session.php b/system/Session/Session.php index 1c3824928775..1998a0ea8596 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -110,11 +110,10 @@ public function start() $this->setSaveHandler(); // Sanitize the cookie, because apparently PHP doesn't do that for userspace handlers - if ( - isset($_COOKIE[$this->config->cookieName]) - && (! is_string($_COOKIE[$this->config->cookieName]) || preg_match('#\A' . $this->sidRegexp . '\z#', $_COOKIE[$this->config->cookieName]) !== 1) - ) { - unset($_COOKIE[$this->config->cookieName]); + $cookie = service('superglobals')->cookie($this->config->cookieName); + + if (isset($cookie) && (! is_string($cookie) || preg_match('#\A' . $this->sidRegexp . '\z#', $cookie) !== 1)) { + service('superglobals')->unsetCookie($this->config->cookieName); } $this->startSession(); @@ -132,7 +131,7 @@ public function start() } // Another work-around ... PHP doesn't seem to send the session cookie // unless it is being currently created or regenerated - elseif (isset($_COOKIE[$this->config->cookieName]) && $_COOKIE[$this->config->cookieName] === session_id()) { + elseif (isset($cookie) && $cookie === session_id()) { $this->setCookie(); } diff --git a/system/Test/FeatureTestTrait.php b/system/Test/FeatureTestTrait.php index a271191a2271..087fc0a59d90 100644 --- a/system/Test/FeatureTestTrait.php +++ b/system/Test/FeatureTestTrait.php @@ -350,9 +350,9 @@ protected function setupRequest(string $method, ?string $path = null): IncomingR $request->setProtocolVersion('1.1'); if ($config->forceGlobalSecureRequests) { - $_SERVER['HTTPS'] = 'test'; - $server = $request->getServer(); - $server['HTTPS'] = 'test'; + service('superglobals')->setServer('HTTPS', 'test'); + $server = $request->getServer(); + $server['HTTPS'] = 'test'; $request->setGlobal('server', $server); } diff --git a/system/Test/Mock/MockSecurity.php b/system/Test/Mock/MockSecurity.php index 89d1eab0a701..072dc548dbe6 100644 --- a/system/Test/Mock/MockSecurity.php +++ b/system/Test/Mock/MockSecurity.php @@ -19,7 +19,7 @@ class MockSecurity extends Security { protected function doSendCookie(): void { - $_COOKIE['csrf_cookie_name'] = $this->hash; + service('superglobals')->setCookie('csrf_cookie_name', $this->hash); } protected function randomize(string $hash): string diff --git a/system/util_bootstrap.php b/system/util_bootstrap.php index 5423954deb59..135208a78ea9 100644 --- a/system/util_bootstrap.php +++ b/system/util_bootstrap.php @@ -23,14 +23,13 @@ * DEFINE ENVIRONMENT * --------------------------------------------------------------- * - * As this bootstrap file is primarily used by internal scripts - * across the framework and other CodeIgniter projects, we need - * to make sure it recognizes that we're in development. + * The environment defaults to development. A caller may set + * $_SERVER['CI_ENVIRONMENT'] before including this file to override it. */ -$_SERVER['CI_ENVIRONMENT'] = 'development'; -define('ENVIRONMENT', 'development'); -defined('CI_DEBUG') || define('CI_DEBUG', true); +$_SERVER['CI_ENVIRONMENT'] ??= 'development'; +defined('ENVIRONMENT') || define('ENVIRONMENT', $_SERVER['CI_ENVIRONMENT']); +defined('CI_DEBUG') || define('CI_DEBUG', true); /* * --------------------------------------------------------------- diff --git a/tests/system/CommonFunctionsSendTest.php b/tests/system/CommonFunctionsSendTest.php index e1f3f9dff961..66e285d26f84 100644 --- a/tests/system/CommonFunctionsSendTest.php +++ b/tests/system/CommonFunctionsSendTest.php @@ -30,7 +30,8 @@ protected function setUp(): void { parent::setUp(); - unset($_ENV['foo'], $_SERVER['foo']); + unset($_ENV['foo']); + service('superglobals')->unsetServer('foo'); } /** diff --git a/tests/system/CommonFunctionsTest.php b/tests/system/CommonFunctionsTest.php index 30f99d79a515..83750c220bc4 100644 --- a/tests/system/CommonFunctionsTest.php +++ b/tests/system/CommonFunctionsTest.php @@ -65,7 +65,8 @@ final class CommonFunctionsTest extends CIUnitTestCase protected function setUp(): void { - unset($_ENV['foo'], $_SERVER['foo']); + unset($_ENV['foo']); + service('superglobals')->unsetServer('foo'); $this->resetServices(); parent::setUp(); diff --git a/tests/system/CommonSingleServiceTest.php b/tests/system/CommonSingleServiceTest.php index e423d1feaee0..829f0f6e2d96 100644 --- a/tests/system/CommonSingleServiceTest.php +++ b/tests/system/CommonSingleServiceTest.php @@ -34,8 +34,8 @@ public function testSingleServiceWithNoParamsSupplied(string $service): void { Services::injectMock('security', new MockSecurity(new SecurityConfig())); - $service1 = single_service($service); // @phpstan-ignore codeigniter.unknownServiceMethod - $service2 = single_service($service); // @phpstan-ignore codeigniter.unknownServiceMethod + $service1 = single_service($service); + $service2 = single_service($service); $this->assertNotNull($service1); @@ -62,8 +62,8 @@ public function testSingleServiceWithAtLeastOneParamSupplied(string $service): v $params[] = $method->getNumberOfParameters() === 1 ? true : $method->getParameters()[0]->getDefaultValue(); - $service1 = single_service($service, ...$params); // @phpstan-ignore codeigniter.unknownServiceMethod - $service2 = single_service($service, ...$params); // @phpstan-ignore codeigniter.unknownServiceMethod + $service1 = single_service($service, ...$params); + $service2 = single_service($service, ...$params); $this->assertNotNull($service1); diff --git a/tests/system/Config/BaseConfigTest.php b/tests/system/Config/BaseConfigTest.php index 1d34ce30535a..24d259feef26 100644 --- a/tests/system/Config/BaseConfigTest.php +++ b/tests/system/Config/BaseConfigTest.php @@ -125,10 +125,7 @@ public function testUseDefaultValueTypeStringValue(): void #[RunInSeparateProcess] public function testServerValues(): void { - $_SERVER = [ - 'simpleconfig.shortie' => 123, - 'SimpleConfig.longie' => 456, - ]; + service('superglobals')->setServerArray(['simpleconfig.shortie' => 123, 'SimpleConfig.longie' => 456]); $dotenv = new DotEnv($this->fixturesFolder, '.env'); $dotenv->load(); $config = new SimpleConfig(); diff --git a/tests/system/Config/DotEnvTest.php b/tests/system/Config/DotEnvTest.php index 505f4bedcbcb..70f14ff79416 100644 --- a/tests/system/Config/DotEnvTest.php +++ b/tests/system/Config/DotEnvTest.php @@ -93,7 +93,8 @@ public static function provideLoadsVars(): iterable public function testLoadsHex2Bin(): void { putenv('encryption.key'); - unset($_ENV['encryption.key'], $_SERVER['encryption.key']); // @phpstan-ignore codeigniter.superglobalAccess + unset($_ENV['encryption.key']); + service('superglobals')->unsetServer('encryption.key'); $dotenv = new DotEnv($this->fixturesFolder, 'encryption.env'); $dotenv->load(); @@ -108,7 +109,8 @@ public function testLoadsHex2Bin(): void public function testLoadsBase64(): void { putenv('encryption.key'); - unset($_ENV['encryption.key'], $_SERVER['encryption.key']); // @phpstan-ignore codeigniter.superglobalAccess + unset($_ENV['encryption.key']); + service('superglobals')->unsetServer('encryption.key'); $dotenv = new DotEnv($this->fixturesFolder, 'base64encryption.env'); $dotenv->load(); @@ -167,10 +169,10 @@ public function testLoadsServerGlobals(): void $dotenv = new DotEnv($this->fixturesFolder, '.env'); $dotenv->load(); - $this->assertSame('bar', $_SERVER['FOO']); - $this->assertSame('baz', $_SERVER['BAR']); - $this->assertSame('with spaces', $_SERVER['SPACED']); - $this->assertSame('', $_SERVER['NULL']); + $this->assertSame('bar', service('superglobals')->server('FOO')); + $this->assertSame('baz', service('superglobals')->server('BAR')); + $this->assertSame('with spaces', service('superglobals')->server('SPACED')); + $this->assertSame('', service('superglobals')->server('NULL')); } public function testNamespacedVariables(): void @@ -178,7 +180,7 @@ public function testNamespacedVariables(): void $dotenv = new DotEnv($this->fixturesFolder, '.env'); $dotenv->load(); - $this->assertSame('complex', $_SERVER['SimpleConfig_simple_name']); + $this->assertSame('complex', service('superglobals')->server('SimpleConfig_simple_name')); } public function testLoadsGetServerVar(): void diff --git a/tests/system/Config/ServicesTest.php b/tests/system/Config/ServicesTest.php index 7eef9818a727..86228dfadd3f 100644 --- a/tests/system/Config/ServicesTest.php +++ b/tests/system/Config/ServicesTest.php @@ -78,7 +78,7 @@ protected function setUp(): void protected function tearDown(): void { - $_SERVER = $this->original; + service('superglobals')->setServerArray($this->original); $this->resetServices(); } diff --git a/tests/system/ControllerTest.php b/tests/system/ControllerTest.php index 113b02c14deb..2ca26f9aa15c 100644 --- a/tests/system/ControllerTest.php +++ b/tests/system/ControllerTest.php @@ -74,7 +74,7 @@ public function testConstructor(): void public function testConstructorHTTPS(): void { $original = $_SERVER; - $_SERVER = ['HTTPS' => 'on']; + service('superglobals')->setServerArray(['HTTPS' => 'on']); // make sure we can instantiate one try { @@ -86,7 +86,7 @@ public function testConstructorHTTPS(): void } $this->assertInstanceOf(Controller::class, $this->controller); - $_SERVER = $original; // restore so code coverage doesn't break + service('superglobals')->setServerArray($original); // restore so code coverage doesn't break } public function testCachePageSetsTtl(): void diff --git a/tests/system/Debug/ExceptionsTest.php b/tests/system/Debug/ExceptionsTest.php index 415b6772c509..919c1ea85180 100644 --- a/tests/system/Debug/ExceptionsTest.php +++ b/tests/system/Debug/ExceptionsTest.php @@ -37,14 +37,14 @@ public static function setUpBeforeClass(): void { parent::setUpBeforeClass(); - unset($_SERVER['CODEIGNITER_SCREAM_DEPRECATIONS']); + service('superglobals')->unsetServer('CODEIGNITER_SCREAM_DEPRECATIONS'); } public static function tearDownAfterClass(): void { parent::tearDownAfterClass(); - $_SERVER['CODEIGNITER_SCREAM_DEPRECATIONS'] = '1'; + service('superglobals')->setServer('CODEIGNITER_SCREAM_DEPRECATIONS', '1'); } protected function setUp(): void diff --git a/tests/system/Entity/EntityTest.php b/tests/system/Entity/EntityTest.php index 52d1de2f5a8b..5233a28deeaf 100644 --- a/tests/system/Entity/EntityTest.php +++ b/tests/system/Entity/EntityTest.php @@ -906,7 +906,7 @@ public function testCastEnumNullable(): void $entity->status = null; - $this->assertNull($entity->status); + $this->assertNotInstanceOf(StatusEnum::class, $entity->status); $entity->status = 'pending'; @@ -1573,7 +1573,7 @@ public function testDataCasterInitEmptyCasts(): void $getDataCaster = $this->getPrivateMethodInvoker($entity, 'dataCaster'); - $this->assertNull($getDataCaster()); + $this->assertNotInstanceOf(DataCaster::class, $getDataCaster()); $this->assertNull($this->getPrivateProperty($entity, 'dataCaster')); $this->assertSame('12345', $entity->first); diff --git a/tests/system/Filters/FiltersTest.php b/tests/system/Filters/FiltersTest.php index cdf57c8b9211..b632df217043 100644 --- a/tests/system/Filters/FiltersTest.php +++ b/tests/system/Filters/FiltersTest.php @@ -68,7 +68,7 @@ protected function setUp(): void ]; service('autoloader')->addNamespace($defaults); - $_SERVER = []; + service('superglobals')->setServerArray([]); Services::injectMock('superglobals', new Superglobals()); $this->response = service('response'); diff --git a/tests/system/HTTP/IncomingRequestTest.php b/tests/system/HTTP/IncomingRequestTest.php index 509cf69643d2..5a7d5f29dfe2 100644 --- a/tests/system/HTTP/IncomingRequestTest.php +++ b/tests/system/HTTP/IncomingRequestTest.php @@ -45,7 +45,13 @@ protected function setUp(): void { parent::setUp(); - $_POST = $_GET = $_SERVER = $_REQUEST = $_ENV = $_COOKIE = $_SESSION = []; + $_ENV = $_SESSION = []; + service('superglobals') + ->setPostArray([]) + ->setGetArray([]) + ->setServerArray([]) + ->setRequestArray([]) + ->setCookieArray([]); Services::injectMock('superglobals', new Superglobals()); $config = new App(); diff --git a/tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php b/tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php index 2a0e485775d4..d9ecd66e7683 100644 --- a/tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php +++ b/tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php @@ -32,7 +32,7 @@ protected function setUp(): void { parent::setUp(); - $_GET = $_SERVER = []; + service('superglobals')->setGetArray([])->setServerArray([]); Services::injectMock('superglobals', new Superglobals()); } @@ -251,7 +251,7 @@ public function testQueryStringWithQueryString(): void $expected = 'ci/woot'; $this->assertSame($expected, $factory->detectRoutePath('QUERY_STRING')); - $this->assertSame('code=good', $_SERVER['QUERY_STRING']); + $this->assertSame('code=good', $_SERVER['QUERY_STRING']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess $this->assertSame(['code' => 'good'], $_GET); } diff --git a/tests/system/Helpers/CookieHelperTest.php b/tests/system/Helpers/CookieHelperTest.php index abbc291ceb38..9b79e8d61dbc 100644 --- a/tests/system/Helpers/CookieHelperTest.php +++ b/tests/system/Helpers/CookieHelperTest.php @@ -41,7 +41,7 @@ final class CookieHelperTest extends CIUnitTestCase protected function setUp(): void { - $_COOKIE = []; + service('superglobals')->setCookieArray([]); parent::setUp(); diff --git a/tests/system/Helpers/FormHelperTest.php b/tests/system/Helpers/FormHelperTest.php index 04c35458cd01..73cbe2430a5f 100644 --- a/tests/system/Helpers/FormHelperTest.php +++ b/tests/system/Helpers/FormHelperTest.php @@ -41,7 +41,7 @@ protected function setUp(): void parent::setUp(); - $_POST = $_GET = []; + service('superglobals')->setPostArray([])->setGetArray([]); CodeIgniterServices::injectMock('superglobals', new Superglobals()); diff --git a/tests/system/Helpers/URLHelper/SiteUrlCliTest.php b/tests/system/Helpers/URLHelper/SiteUrlCliTest.php index e24f55f44605..ad99f46a8b2a 100644 --- a/tests/system/Helpers/URLHelper/SiteUrlCliTest.php +++ b/tests/system/Helpers/URLHelper/SiteUrlCliTest.php @@ -48,7 +48,7 @@ protected function tearDown(): void { parent::tearDown(); - $_SERVER = []; + service('superglobals')->setServerArray([]); } private function createRequest(?App $config = null): void diff --git a/tests/system/Helpers/URLHelper/SiteUrlTest.php b/tests/system/Helpers/URLHelper/SiteUrlTest.php index 791515a09fab..c8a07758e3bd 100644 --- a/tests/system/Helpers/URLHelper/SiteUrlTest.php +++ b/tests/system/Helpers/URLHelper/SiteUrlTest.php @@ -52,7 +52,7 @@ protected function tearDown(): void { parent::tearDown(); - $_SERVER = []; + service('superglobals')->setServerArray([]); } private function createRequest(?App $config = null, $body = null, ?string $path = null): void diff --git a/tests/system/Models/DataConverterModelTest.php b/tests/system/Models/DataConverterModelTest.php index 7d647790d62b..f26f03d999b9 100644 --- a/tests/system/Models/DataConverterModelTest.php +++ b/tests/system/Models/DataConverterModelTest.php @@ -20,6 +20,7 @@ use Tests\Support\Models\UserCastsTimestampModel; /** + * @property-read UserCastsTimestampModel $model * @internal */ #[Group('DatabaseLive')] @@ -36,7 +37,7 @@ public function testFindAsArray(): void $user = $this->model->find($id); - $this->assertIsInt($user['id']); // @phpstan-ignore offsetAccess.notFound + $this->assertIsInt($user['id']); $this->assertInstanceOf(Time::class, $user['created_at']); $this->assertSame('John Smith', $user['name']); // `name` is cast by custom CastBase64 handler. @@ -128,9 +129,9 @@ public function testFindAllAsArray(): void $users = $this->model->findAll(); - $this->assertIsInt($users[0]['id']); // @phpstan-ignore offsetAccess.notFound + $this->assertIsInt($users[0]['id']); $this->assertInstanceOf(Time::class, $users[0]['created_at']); - $this->assertIsInt($users[1]['id']); // @phpstan-ignore offsetAccess.notFound + $this->assertIsInt($users[1]['id']); $this->assertInstanceOf(Time::class, $users[1]['created_at']); } @@ -208,7 +209,7 @@ public function testFirstAsArray(): void $user = $this->model->first(); - $this->assertIsInt($user['id']); // @phpstan-ignore offsetAccess.notFound + $this->assertIsInt($user['id']); $this->assertInstanceOf(Time::class, $user['created_at']); } @@ -265,7 +266,7 @@ public function testInsertArray(): void $user = $this->model->find($id); - $this->assertSame(['joe@example.com'], $user['email']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame(['joe@example.com'], $user['email']); } public function testInsertObject(): void @@ -281,7 +282,7 @@ public function testInsertObject(): void $user = $this->model->find($id); - $this->assertSame(['joe@example.com'], $user['email']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame(['joe@example.com'], $user['email']); } public function testUpdateArray(): void @@ -290,14 +291,14 @@ public function testUpdateArray(): void $user = $this->model->find($id); $user['email'][] = 'private@example.org'; - $this->model->update($user['id'], $user); // @phpstan-ignore offsetAccess.notFound + $this->model->update($user['id'], $user); $user = $this->model->find($id); $this->assertSame([ 'john@example.com', 'private@example.org', - ], $user['email']); // @phpstan-ignore offsetAccess.notFound + ], $user['email']); } public function testUpdateObject(): void @@ -313,7 +314,7 @@ public function testUpdateObject(): void $this->assertSame([ 'john@example.com', 'private@example.org', - ], $user['email']); // @phpstan-ignore offsetAccess.notFound + ], $user['email']); } public function testUpdateCustomObject(): void @@ -335,8 +336,7 @@ public function testUpdateCustomObject(): void public function testUpdateEntity(): void { - $id = $this->prepareOneRecord(); - /** @var User $user */ + $id = $this->prepareOneRecord(); $user = $this->model->asObject(User::class)->find($id); $email = $user->email; @@ -365,7 +365,7 @@ public function testSaveArray(): void $this->assertSame([ 'john@example.com', 'private@example.org', - ], $user['email']); // @phpstan-ignore offsetAccess.notFound + ], $user['email']); } public function testSaveObject(): void @@ -381,7 +381,7 @@ public function testSaveObject(): void $this->assertSame([ 'john@example.com', 'private@example.org', - ], $user['email']); // @phpstan-ignore offsetAccess.notFound + ], $user['email']); } public function testSaveCustomObject(): void @@ -403,8 +403,7 @@ public function testSaveCustomObject(): void public function testSaveEntity(): void { - $id = $this->prepareOneRecord(); - /** @var User $user */ + $id = $this->prepareOneRecord(); $user = $this->model->asObject(User::class)->find($id); $email = $user->email; diff --git a/tests/system/Models/FindModelTest.php b/tests/system/Models/FindModelTest.php index 71a085dc3950..b5efc8a64f64 100644 --- a/tests/system/Models/FindModelTest.php +++ b/tests/system/Models/FindModelTest.php @@ -226,27 +226,27 @@ public function testFirstRespectsSoftDeletes($aggregate, $groupBy): void ->where('id', 1) ->update(['deleted_at' => date('Y-m-d H:i:s')]); - $this->createModel(UserModel::class); + $model = $this->createModel(UserModel::class); if ($aggregate) { $ANSISQLDriverNames = ['OCI8']; if (in_array($this->db->DBDriver, $ANSISQLDriverNames, true)) { - $this->model->select('SUM("id") as "id"'); + $model->select('SUM("id") as "id"'); } else { - $this->model->select('SUM(id) as id'); + $model->select('SUM(id) as id'); } } if ($groupBy) { if (! $aggregate) { - $this->model->select('id'); + $model->select('id'); } - $this->model->groupBy('id'); + $model->groupBy('id'); } - $user = $this->model->first(); + $user = $model->first(); if (! $aggregate || $groupBy) { $count = is_object($user) ? 1 : 0; @@ -256,7 +256,7 @@ public function testFirstRespectsSoftDeletes($aggregate, $groupBy): void $this->assertSame(9, (int) $user->id); } - $user = $this->model->withDeleted()->select('id')->first(); + $user = $model->withDeleted()->select('id')->first(); $this->assertSame(1, (int) $user->id); } @@ -267,29 +267,29 @@ public function testFirstRespectsSoftDeletes($aggregate, $groupBy): void #[DataProvider('provideAggregateAndGroupBy')] public function testFirstRecoverTempUseSoftDeletes($aggregate, $groupBy): void { - $this->createModel(UserModel::class); - $this->model->delete(1); + $model = $this->createModel(UserModel::class); + $model->delete(1); if ($aggregate) { $ANSISQLDriverNames = ['OCI8']; if (in_array($this->db->DBDriver, $ANSISQLDriverNames, true)) { - $this->model->select('SUM("id") as "id"'); + $model->select('SUM("id") as "id"'); } else { - $this->model->select('SUM(id) as id'); + $model->select('SUM(id) as id'); } } else { - $this->model->select('id'); + $model->select('id'); } if ($groupBy) { - $this->model->groupBy('id'); + $model->groupBy('id'); } - $user = $this->model->withDeleted()->first(); + $user = $model->withDeleted()->first(); $this->assertSame(1, (int) $user->id); - $user2 = $this->model->select('id')->first(); + $user2 = $model->select('id')->first(); $this->assertSame(2, (int) $user2->id); } diff --git a/tests/system/Models/InsertModelTest.php b/tests/system/Models/InsertModelTest.php index 74a2ffaa89fa..ccaa8e9cf4ac 100644 --- a/tests/system/Models/InsertModelTest.php +++ b/tests/system/Models/InsertModelTest.php @@ -119,12 +119,12 @@ public function testInsertBatchSetsIntTimestamps(): void ], ]; - $this->createModel(JobModel::class); + $model = $this->createModel(JobModel::class); - $this->setPrivateProperty($this->model, 'useTimestamps', true); - $this->assertSame(2, $this->model->insertBatch($jobData)); + $this->setPrivateProperty($model, 'useTimestamps', true); + $this->assertSame(2, $model->insertBatch($jobData)); - $result = $this->model->where('name', 'Philosopher')->first(); + $result = $model->where('name', 'Philosopher')->first(); $this->assertCloseEnough(time(), (int) $result->created_at); } @@ -143,12 +143,12 @@ public function testInsertBatchSetsDatetimeTimestamps(): void ], ]; - $this->createModel(UserModel::class); + $model = $this->createModel(UserModel::class); - $this->setPrivateProperty($this->model, 'useTimestamps', true); - $this->assertSame(2, $this->model->insertBatch($userData)); + $this->setPrivateProperty($model, 'useTimestamps', true); + $this->assertSame(2, $model->insertBatch($userData)); - $result = $this->model->where('name', 'Lou')->first(); + $result = $model->where('name', 'Lou')->first(); $this->assertCloseEnough(time(), strtotime($result->created_at)); } @@ -335,15 +335,13 @@ public function testInsertWithSetAndEscape(): void 'name' => 'Scott', ]; - $this->createModel(UserModel::class); - - $this->setPrivateProperty($this->model, 'useTimestamps', true); - - $this->model->set('country', '1+1', false)->set('email', '2+2')->insert($userData); + $model = $this->createModel(UserModel::class); + $this->setPrivateProperty($model, 'useTimestamps', true); - $this->assertGreaterThan(0, $this->model->getInsertID()); - $result = $this->model->where('name', 'Scott')->where('country', '2')->where('email', '2+2')->first(); + $model->set('country', '1+1', false)->set('email', '2+2')->insert($userData); + $this->assertGreaterThan(0, $model->getInsertID()); + $result = $model->where('name', 'Scott')->where('country', '2')->where('email', '2+2')->first(); $this->assertNotNull($result->created_at); } @@ -389,7 +387,7 @@ public function testInsertBatchWithCasts(): void ]; $this->createModel(UserCastsTimestampModel::class); - $numRows = $this->model->insertBatch($userData); // @phpstan-ignore argument.type + $numRows = $this->model->insertBatch($userData); $this->assertSame(2, $numRows); diff --git a/tests/system/Models/MiscellaneousModelTest.php b/tests/system/Models/MiscellaneousModelTest.php index e95a709e61bd..ae6d98621819 100644 --- a/tests/system/Models/MiscellaneousModelTest.php +++ b/tests/system/Models/MiscellaneousModelTest.php @@ -99,7 +99,8 @@ public function testChunkEmptyTable(): void public function testCanCreateAndSaveEntityClasses(): void { - $entity = $this->createModel(EntityModel::class)->where('name', 'Developer')->first(); + $model = $this->createModel(EntityModel::class); + $entity = $model->where('name', 'Developer')->first(); $this->assertInstanceOf(SimpleEntity::class, $entity); $this->assertSame('Developer', $entity->name); @@ -110,9 +111,9 @@ public function testCanCreateAndSaveEntityClasses(): void $entity->name = 'Senior Developer'; $entity->created_at = $time; - $this->assertTrue($this->model->save($entity)); + $this->assertTrue($model->save($entity)); - $result = $this->model->where('name', 'Senior Developer')->first(); + $result = $model->where('name', 'Senior Developer')->first(); $this->assertSame( Time::createFromTimestamp($time)->toDateTimeString(), $result->created_at->toDateTimeString(), diff --git a/tests/system/Models/SaveModelTest.php b/tests/system/Models/SaveModelTest.php index be77d958ff7f..246bd8e6142c 100644 --- a/tests/system/Models/SaveModelTest.php +++ b/tests/system/Models/SaveModelTest.php @@ -167,9 +167,9 @@ public function testSelectAndEntitiesSaveOnlyChangedValues(): void 'created_at' => time(), ]); - $this->createModel(EntityModel::class); + $model = $this->createModel(EntityModel::class); - $job = $this->model->select('id, name')->where('name', 'Rocket Scientist')->first(); + $job = $model->select('id, name')->where('name', 'Rocket Scientist')->first(); $this->assertNull($job->description); $this->assertSame('Rocket Scientist', $job->name); @@ -181,7 +181,7 @@ public function testSelectAndEntitiesSaveOnlyChangedValues(): void 'name' => 'Rocket Scientist', ]); - $job = $this->model->select('id, name, description')->where('name', 'Rocket Scientist')->first(); + $job = $model->select('id, name, description')->where('name', 'Rocket Scientist')->first(); $this->assertSame('Some guitar description', $job->description); } diff --git a/tests/system/Models/TimestampModelTest.php b/tests/system/Models/TimestampModelTest.php index 9af7cd3b9547..52989cff754a 100644 --- a/tests/system/Models/TimestampModelTest.php +++ b/tests/system/Models/TimestampModelTest.php @@ -19,6 +19,7 @@ use Tests\Support\Models\UserTimestampModel; /** + * @property-read UserTimestampModel $model * @internal */ #[Group('DatabaseLive')] @@ -98,7 +99,7 @@ public function testDoNotAllowDatesInsertArrayWithoutDatesSetsTimestamp(): void $expected .= '.000'; } - $this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame($expected, $user['created_at']); $this->assertSame($expected, $user['updated_at']); } @@ -123,7 +124,7 @@ public function testDoNotAllowDatesInsertArrayWithDatesSetsTimestamp(): void $expected .= '.000'; } - $this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame($expected, $user['created_at']); $this->assertSame($expected, $user['updated_at']); } @@ -143,7 +144,7 @@ public function testDoNotAllowDatesUpdateArrayUpdatesUpdatedAt(): void $user = $this->model->find($id); $user['country'] = 'CA'; - $this->model->update($user['id'], $user); // @phpstan-ignore offsetAccess.notFound + $this->model->update($user['id'], $user); $user = $this->model->find($id); @@ -153,7 +154,7 @@ public function testDoNotAllowDatesUpdateArrayUpdatesUpdatedAt(): void $expected .= '.000'; } - $this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame($expected, $user['created_at']); $this->assertSame($expected, $user['updated_at']); } @@ -170,14 +171,13 @@ public function testDoNotAllowDatesUpdateEntityUpdatesUpdatedAt(): void ]; $id = $this->doNotAllowDatesPrepareOneRecord($data); $this->setPrivateProperty($this->model, 'returnType', User::class); - $this->setPrivateProperty($this->model, 'tempReturnType', User::class); - $user = $this->model->find($id); + $user = $this->model->asObject(User::class)->find($id); $user->country = 'CA'; $this->model->update($user->id, $user); - $user = $this->model->find($id); + $user = $this->model->asObject(User::class)->find($id); $this->assertSame('2023-11-25 12:00:00', (string) $user->created_at); $this->assertSame('2023-11-25 12:00:00', (string) $user->updated_at); @@ -208,7 +208,7 @@ public function testAllowDatesInsertArrayWithoutDatesSetsTimestamp(): void $expected .= '.000'; } - $this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame($expected, $user['created_at']); $this->assertSame($expected, $user['updated_at']); } @@ -237,7 +237,7 @@ public function testAllowDatesInsertArrayWithDatesSetsTimestamp(): void $expected .= '.000'; } - $this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame($expected, $user['created_at']); $this->assertSame($expected, $user['updated_at']); } @@ -261,7 +261,7 @@ public function testAllowDatesUpdateArrayUpdatesUpdatedAt(): void $user = $this->model->find($id); $user['country'] = 'CA'; - $this->model->update($user['id'], $user); // @phpstan-ignore offsetAccess.notFound + $this->model->update($user['id'], $user); $user = $this->model->find($id); @@ -271,7 +271,7 @@ public function testAllowDatesUpdateArrayUpdatesUpdatedAt(): void $expected .= '.000'; } - $this->assertSame($expected, $user['created_at']); // @phpstan-ignore offsetAccess.notFound + $this->assertSame($expected, $user['created_at']); $this->assertSame($expected, $user['updated_at']); } @@ -292,14 +292,13 @@ public function testAllowDatesUpdateEntityUpdatesUpdatedAt(): void ]; $id = $this->allowDatesPrepareOneRecord($data); $this->setPrivateProperty($this->model, 'returnType', User::class); - $this->setPrivateProperty($this->model, 'tempReturnType', User::class); - $user = $this->model->find($id); + $user = $this->model->asObject(User::class)->find($id); $user->country = 'CA'; $this->model->update($user->id, $user); - $user = $this->model->find($id); + $user = $this->model->asObject(User::class)->find($id); $this->assertSame('2000-01-01 12:00:00', (string) $user->created_at); // The Entity has `updated_at` value, but it will be discarded because of onlyChanged. diff --git a/tests/system/Models/UpdateModelTest.php b/tests/system/Models/UpdateModelTest.php index ed2ebf7a9a93..23279dc5b968 100644 --- a/tests/system/Models/UpdateModelTest.php +++ b/tests/system/Models/UpdateModelTest.php @@ -422,7 +422,6 @@ public function testUpdateSetObject(): void /** @var int|string $id */ $id = $this->model->insert($object); - /** @var stdClass $object */ $object = $this->model->find($id); $object->name = 'John Smith'; @@ -457,30 +456,27 @@ public function testUpdateSetEntity(): void public function testUpdateEntityWithPrimaryKeyCast(): void { - if ( - in_array($this->db->DBDriver, ['OCI8', 'Postgre', 'SQLSRV', 'SQLite3'], true) - ) { + if (in_array($this->db->DBDriver, ['OCI8', 'Postgre', 'SQLSRV', 'SQLite3'], true)) { $this->markTestSkipped($this->db->DBDriver . ' does not work with binary data as string data.'); } $this->createUuidTable(); - $this->createModel(UUIDPkeyModel::class); + $model = $this->createModel(UUIDPkeyModel::class); $entity = new UUID(); $entity->id = '550e8400-e29b-41d4-a716-446655440000'; $entity->value = 'test1'; - $id = $this->model->insert($entity); - $entity = $this->model->find($id); + $id = $model->insert($entity); + $entity = $model->find($id); $entity->value = 'id'; - $result = $this->model->save($entity); + $result = $model->save($entity); $this->assertTrue($result); - $entity = $this->model->find($id); - + $entity = $model->find($id); $this->assertSame('id', $entity->value); } @@ -716,7 +712,7 @@ public function testUpdateBatchWithCasts(): void ], ]; - $numRows = $this->model->updateBatch($updateData, 'id'); // @phpstan-ignore argument.type + $numRows = $this->model->updateBatch($updateData, 'id'); $this->assertSame(2, $numRows); $this->seeInDatabase('user', ['email' => json_encode($updateData[0]['email'])]); diff --git a/tests/system/Models/WhenWhenNotModelTest.php b/tests/system/Models/WhenWhenNotModelTest.php index 31015aa88bb1..aa9edffe9efe 100644 --- a/tests/system/Models/WhenWhenNotModelTest.php +++ b/tests/system/Models/WhenWhenNotModelTest.php @@ -40,9 +40,10 @@ public function testWhenWithTrueCondition(): void ]; $filter = 'foobar'; - $this->createModel(SecondaryModel::class)->insertBatch($secondaryData); + $model = $this->createModel(SecondaryModel::class); + $model->insertBatch($secondaryData); - $result = $this->model->when($filter, static function ($query, $filter): void { + $result = $model->when($filter, static function ($query, $filter): void { $query->where('value', $filter); })->find(); @@ -69,9 +70,10 @@ public function testWhenWithFalseConditionAndDefaultCallback(): void ]; $filter = ''; - $this->createModel(SecondaryModel::class)->insertBatch($secondaryData); + $model = $this->createModel(SecondaryModel::class); + $model->insertBatch($secondaryData); - $result = $this->model->when($filter, static function ($query, $filter): void { + $result = $model->when($filter, static function ($query, $filter): void { $query->where('value', $filter); }, static function ($query): void { $query->where('value', 'foobar'); @@ -100,9 +102,10 @@ public function testWhenNotWithFalseCondition(): void ]; $filter = ''; - $this->createModel(SecondaryModel::class)->insertBatch($secondaryData); + $model = $this->createModel(SecondaryModel::class); + $model->insertBatch($secondaryData); - $result = $this->model->whenNot($filter, static function ($query, $filter): void { + $result = $model->whenNot($filter, static function ($query, $filter): void { $query->where('value !=', 'foobar'); })->find(); @@ -129,9 +132,10 @@ public function testWhenNotWithTrueConditionAndDefaultCallback(): void ]; $filter = 'foobar'; - $this->createModel(SecondaryModel::class)->insertBatch($secondaryData); + $model = $this->createModel(SecondaryModel::class); + $model->insertBatch($secondaryData); - $result = $this->model->whenNot($filter, static function ($query, $filter): void { + $result = $model->whenNot($filter, static function ($query, $filter): void { $query->where('value !=', 'foobar'); }, static function ($query): void { $query->where('value', 'foobar'); diff --git a/tests/system/SuperglobalsTest.php b/tests/system/SuperglobalsTest.php index b7a2af0edcd7..f679aaca0273 100644 --- a/tests/system/SuperglobalsTest.php +++ b/tests/system/SuperglobalsTest.php @@ -40,7 +40,7 @@ public function testServerGetSet(): void $this->superglobals->setServer('TEST_KEY', 'test_value'); $this->assertSame('test_value', $this->superglobals->server('TEST_KEY')); - $this->assertSame('test_value', $_SERVER['TEST_KEY']); + $this->assertSame('test_value', $_SERVER['TEST_KEY']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess } public function testServerGetReturnsNullForNonExistent(): void @@ -108,7 +108,7 @@ public function testGetGetSet(): void $this->superglobals->setGet('test', 'value1'); $this->assertSame('value1', $this->superglobals->get('test')); - $this->assertSame('value1', $_GET['test']); + $this->assertSame('value1', $_GET['test']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess } public function testGetReturnsNullForNonExistent(): void @@ -158,7 +158,7 @@ public function testPostGetSet(): void $this->superglobals->setPost('test', 'value1'); $this->assertSame('value1', $this->superglobals->post('test')); - $this->assertSame('value1', $_POST['test']); + $this->assertSame('value1', $_POST['test']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess } public function testPostReturnsNullForNonExistent(): void @@ -208,7 +208,7 @@ public function testCookieGetSet(): void $this->superglobals->setCookie('session', 'abc123'); $this->assertSame('abc123', $this->superglobals->cookie('session')); - $this->assertSame('abc123', $_COOKIE['session']); + $this->assertSame('abc123', $_COOKIE['session']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess } public function testCookieReturnsNullForNonExistent(): void @@ -258,7 +258,7 @@ public function testRequestGetSet(): void $this->superglobals->setRequest('test', 'value1'); $this->assertSame('value1', $this->superglobals->request('test')); - $this->assertSame('value1', $_REQUEST['test']); + $this->assertSame('value1', $_REQUEST['test']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess } public function testRequestReturnsNullForNonExistent(): void @@ -475,11 +475,11 @@ public function testConstructorSynchronizesWithPhpSuperglobals(): void new Superglobals($server, $get, $post, $cookie, $files, $request); // Verify PHP superglobals are synchronized - $this->assertSame('server_val', $_SERVER['CUSTOM_SERVER']); - $this->assertSame('get_val', $_GET['custom_get']); - $this->assertSame('post_val', $_POST['custom_post']); - $this->assertSame('cookie_val', $_COOKIE['custom_cookie']); - $this->assertSame('request_val', $_REQUEST['custom_request']); + $this->assertSame('server_val', $_SERVER['CUSTOM_SERVER']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess + $this->assertSame('get_val', $_GET['custom_get']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess + $this->assertSame('post_val', $_POST['custom_post']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess + $this->assertSame('cookie_val', $_COOKIE['custom_cookie']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess + $this->assertSame('request_val', $_REQUEST['custom_request']); // @phpstan-ignore codeigniter.superglobalsOffsetAccess $this->assertSame($files, $_FILES); } diff --git a/user_guide_src/source/installation/upgrade_412.rst b/user_guide_src/source/installation/upgrade_412.rst index 1fec935f7ec6..3d3f0aa4051a 100644 --- a/user_guide_src/source/installation/upgrade_412.rst +++ b/user_guide_src/source/installation/upgrade_412.rst @@ -143,9 +143,6 @@ many will be simple comments or formatting that have no effect on the runtime: * ``composer.json`` * ``contributing/guidelines.rst`` * ``env`` -* ``phpstan.neon.dist`` -* ``phpunit.xml.dist`` * ``public/.htaccess`` * ``public/index.php`` -* ``rector.php`` * ``spark`` diff --git a/utils/phpstan-baseline/argument.type.neon b/utils/phpstan-baseline/argument.type.neon index 9697915545a3..bbd0685fcf76 100644 --- a/utils/phpstan-baseline/argument.type.neon +++ b/utils/phpstan-baseline/argument.type.neon @@ -1,4 +1,4 @@ -# total 78 errors +# total 73 errors parameters: ignoreErrors: @@ -177,21 +177,6 @@ parameters: count: 1 path: ../../tests/system/Log/Handlers/ChromeLoggerHandlerTest.php - - - message: '#^Parameter \#1 \$row of method CodeIgniter\\BaseModel\:\:save\(\) expects array\\|object, array\\> given\.$#' - count: 1 - path: ../../tests/system/Models/DataConverterModelTest.php - - - - message: '#^Parameter \#1 \$row of method CodeIgniter\\Model\:\:insert\(\) expects array\\|object\|null, array\\|string\> given\.$#' - count: 3 - path: ../../tests/system/Models/DataConverterModelTest.php - - - - message: '#^Parameter \#2 \$row of method CodeIgniter\\Model\:\:update\(\) expects array\\|object\|null, array\\> given\.$#' - count: 1 - path: ../../tests/system/Models/DataConverterModelTest.php - - message: '#^Parameter \#1 \$format of method CodeIgniter\\RESTful\\ResourceController\:\:setFormat\(\) expects ''json''\|''xml'', ''Nonsense'' given\.$#' count: 1 diff --git a/utils/phpstan-baseline/codeigniter.getReassignArray.neon b/utils/phpstan-baseline/codeigniter.getReassignArray.neon deleted file mode 100644 index f663c67ee50e..000000000000 --- a/utils/phpstan-baseline/codeigniter.getReassignArray.neon +++ /dev/null @@ -1,18 +0,0 @@ -# total 3 errors - -parameters: - ignoreErrors: - - - message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#' - count: 1 - path: ../../tests/system/HTTP/IncomingRequestTest.php - - - - message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#' - count: 1 - path: ../../tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php - - - - message: '#^Re\-assigning arrays to \$_GET directly is discouraged\.$#' - count: 1 - path: ../../tests/system/Helpers/FormHelperTest.php diff --git a/utils/phpstan-baseline/codeigniter.superglobalAccess.neon b/utils/phpstan-baseline/codeigniter.superglobalAccess.neon deleted file mode 100644 index 68f9316f8ee1..000000000000 --- a/utils/phpstan-baseline/codeigniter.superglobalAccess.neon +++ /dev/null @@ -1,123 +0,0 @@ -# total 29 errors - -parameters: - ignoreErrors: - - - message: '#^Accessing offset ''ANSICON'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Accessing offset ''NO_COLOR'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/CLI/CLI.php - - - - message: '#^Accessing offset ''encryption\.key'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/Commands/Encryption/GenerateKey.php - - - - message: '#^Accessing offset ''REMOTE_ADDR'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/Common.php - - - - message: '#^Accessing offset ''REQUEST_METHOD'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/Common.php - - - - message: '#^Accessing offset string directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/Common.php - - - - message: '#^Accessing offset ''CI_ENVIRONMENT'' directly on \$_SERVER is discouraged\.$#' - count: 2 - path: ../../system/Config/AutoloadConfig.php - - - - message: '#^Accessing offset non\-falsy\-string directly on \$_SERVER is discouraged\.$#' - count: 4 - path: ../../system/Config/BaseConfig.php - - - - message: '#^Accessing offset string directly on \$_SERVER is discouraged\.$#' - count: 2 - path: ../../system/Config/DotEnv.php - - - - message: '#^Accessing offset string directly on \$_GET is discouraged\.$#' - count: 1 - path: ../../system/Superglobals.php - - - - message: '#^Accessing offset string directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/Superglobals.php - - - - message: '#^Accessing offset ''foo'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/CommonFunctionsSendTest.php - - - - message: '#^Accessing offset ''foo'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/CommonFunctionsTest.php - - - - message: '#^Accessing offset ''BAR'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Config/DotEnvTest.php - - - - message: '#^Accessing offset ''FOO'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Config/DotEnvTest.php - - - - message: '#^Accessing offset ''NULL'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Config/DotEnvTest.php - - - - message: '#^Accessing offset ''SPACED'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Config/DotEnvTest.php - - - - message: '#^Accessing offset ''SimpleConfig_simple_name'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Config/DotEnvTest.php - - - - message: '#^Accessing offset ''CODEIGNITER_SCREAM_DEPRECATIONS'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Debug/ExceptionsTest.php - - - - message: '#^Accessing offset ''QUERY_STRING'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/HTTP/SiteURIFactoryDetectRoutePathTest.php - - - - message: '#^Accessing offset ''CUSTOM_SERVER'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/SuperglobalsTest.php - - - - message: '#^Accessing offset ''TEST_KEY'' directly on \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/SuperglobalsTest.php - - - - message: '#^Accessing offset ''custom_get'' directly on \$_GET is discouraged\.$#' - count: 1 - path: ../../tests/system/SuperglobalsTest.php - - - - message: '#^Accessing offset ''test'' directly on \$_GET is discouraged\.$#' - count: 1 - path: ../../tests/system/SuperglobalsTest.php diff --git a/utils/phpstan-baseline/codeigniter.superglobalAccessAssign.neon b/utils/phpstan-baseline/codeigniter.superglobalAccessAssign.neon deleted file mode 100644 index ab0d015d5677..000000000000 --- a/utils/phpstan-baseline/codeigniter.superglobalAccessAssign.neon +++ /dev/null @@ -1,28 +0,0 @@ -# total 5 errors - -parameters: - ignoreErrors: - - - message: '#^Assigning string directly on offset string of \$_SERVER is discouraged\.$#' - count: 1 - path: ../../system/Config/DotEnv.php - - - - message: '#^Assigning ''1'' directly on offset ''CODEIGNITER_SCREAM_DEPRECATIONS'' of \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Debug/ExceptionsTest.php - - - - message: '#^Assigning ''test'' directly on offset ''HTTPS'' of \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/HomeTest.php - - - - message: '#^Assigning ''test'' directly on offset ''HTTPS'' of \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestAutoRoutingImprovedTest.php - - - - message: '#^Assigning ''test'' directly on offset ''HTTPS'' of \$_SERVER is discouraged\.$#' - count: 1 - path: ../../tests/system/Test/FeatureTestTraitTest.php diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 405c9a54ac16..672ff3a32e43 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,13 +1,10 @@ -# total 2012 errors +# total 1944 errors includes: - argument.type.neon - arguments.count.neon - assign.propertyType.neon - - codeigniter.getReassignArray.neon - codeigniter.modelArgumentType.neon - - codeigniter.superglobalAccess.neon - - codeigniter.superglobalAccessAssign.neon - deadCode.unreachable.neon - empty.notAllowed.neon - function.resultUnused.neon diff --git a/utils/phpstan-baseline/property.nonObject.neon b/utils/phpstan-baseline/property.nonObject.neon index 33d6299465f8..7268e376d119 100644 --- a/utils/phpstan-baseline/property.nonObject.neon +++ b/utils/phpstan-baseline/property.nonObject.neon @@ -1,4 +1,4 @@ -# total 36 errors +# total 12 errors parameters: ignoreErrors: @@ -27,61 +27,6 @@ parameters: count: 1 path: ../../tests/system/Database/Live/GetTest.php - - - message: '#^Cannot access property \$id on array\.$#' - count: 2 - path: ../../tests/system/Models/FindModelTest.php - - - - message: '#^Cannot access property \$created_at on array\.$#' - count: 3 - path: ../../tests/system/Models/InsertModelTest.php - - - - message: '#^Cannot access property \$created_at on array\.$#' - count: 1 - path: ../../tests/system/Models/MiscellaneousModelTest.php - - - - message: '#^Cannot access property \$description on array\.$#' - count: 1 - path: ../../tests/system/Models/SaveModelTest.php - - - - message: '#^Cannot access property \$country on array\.$#' - count: 2 - path: ../../tests/system/Models/TimestampModelTest.php - - - - message: '#^Cannot access property \$created_at on array\.$#' - count: 2 - path: ../../tests/system/Models/TimestampModelTest.php - - - - message: '#^Cannot access property \$id on array\.$#' - count: 2 - path: ../../tests/system/Models/TimestampModelTest.php - - - - message: '#^Cannot access property \$updated_at on array\.$#' - count: 2 - path: ../../tests/system/Models/TimestampModelTest.php - - - - message: '#^Cannot access property \$value on list\\.$#' - count: 1 - path: ../../tests/system/Models/UpdateModelTest.php - - - - message: '#^Cannot access property \$key on array\.$#' - count: 7 - path: ../../tests/system/Models/WhenWhenNotModelTest.php - - - - message: '#^Cannot access property \$value on array\.$#' - count: 1 - path: ../../tests/system/Models/WhenWhenNotModelTest.php - - message: '#^Cannot access property \$created_at on array\|object\.$#' count: 1