From e5d1848d3cb594e5cb3977cda0baeefe87e681a3 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Wed, 2 Aug 2023 17:27:56 +0800 Subject: [PATCH 1/4] Dev: Remove the config ignore errors. --- phpstan-baseline.php | 65 ----------------------------- system/Config/BaseConfig.php | 2 + system/Config/BaseService.php | 6 +++ system/Config/Config.php | 4 ++ system/Config/DotEnv.php | 2 + system/Config/Factories.php | 4 ++ system/Config/ForeignCharacters.php | 2 + system/Config/Publisher.php | 2 + system/Config/View.php | 4 ++ 9 files changed, 26 insertions(+), 65 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 9665737db821..58ade466d21c 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -316,71 +316,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/ComposerScripts.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\BaseConfig\\:\\:registerProperties\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/BaseConfig.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\BaseService\\:\\:injectMock\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/BaseService.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\BaseService\\:\\:reset\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/BaseService.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\BaseService\\:\\:resetSingle\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/BaseService.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\Config\\:\\:injectMock\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/Config.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\Config\\:\\:reset\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/Config.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\DotEnv\\:\\:setVariable\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/DotEnv.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\Factories\\:\\:injectMock\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/Factories.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\Factories\\:\\:reset\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/Factories.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Config\\\\ForeignCharacters\\:\\:\\$characterList has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/ForeignCharacters.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Method CodeIgniter\\\\Config\\\\Publisher\\:\\:registerProperties\\(\\) has no return type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/Publisher.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$filters has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/View.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$plugins has no type specified\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/View.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Controller\\:\\:cachePage\\(\\) has no return type specified\\.$#', 'count' => 1, diff --git a/system/Config/BaseConfig.php b/system/Config/BaseConfig.php index 80ae268635ef..0958d7ae7f75 100644 --- a/system/Config/BaseConfig.php +++ b/system/Config/BaseConfig.php @@ -169,6 +169,8 @@ protected function getEnvValue(string $property, string $prefix, string $shortPr * Provides external libraries a simple way to register one or more * options into a config file. * + * @return void + * * @throws ReflectionException */ protected function registerProperties() diff --git a/system/Config/BaseService.php b/system/Config/BaseService.php index d517691b0c1f..e41c0c0ed06f 100644 --- a/system/Config/BaseService.php +++ b/system/Config/BaseService.php @@ -273,6 +273,8 @@ public static function serviceExists(string $name): ?string /** * Reset shared instances and mocks for testing. + * + * @return void */ public static function reset(bool $initAutoloader = true) { @@ -286,6 +288,8 @@ public static function reset(bool $initAutoloader = true) /** * Resets any mock and shared instances for a single service. + * + * @return void */ public static function resetSingle(string $name) { @@ -297,6 +301,8 @@ public static function resetSingle(string $name) * Inject mock object for testing. * * @param object $mock + * + * @return void */ public static function injectMock(string $name, $mock) { diff --git a/system/Config/Config.php b/system/Config/Config.php index d261fa4d9ae4..3008865b29fa 100644 --- a/system/Config/Config.php +++ b/system/Config/Config.php @@ -34,6 +34,8 @@ public static function get(string $name, bool $getShared = true) * Helper method for injecting mock instances while testing. * * @param object $instance + * + * @return void */ public static function injectMock(string $name, $instance) { @@ -42,6 +44,8 @@ public static function injectMock(string $name, $instance) /** * Resets the static arrays + * + * @return void */ public static function reset() { diff --git a/system/Config/DotEnv.php b/system/Config/DotEnv.php index 724524e2d590..0275b5c4b9c3 100644 --- a/system/Config/DotEnv.php +++ b/system/Config/DotEnv.php @@ -85,6 +85,8 @@ public function parse(): ?array * Sets the variable into the environment. Will parse the string * first to look for {name}={value} pattern, ensure that nested * variables are handled, and strip it of single and double quotes. + * + * @return void */ protected function setVariable(string $name, string $value = '') { diff --git a/system/Config/Factories.php b/system/Config/Factories.php index 222df063196a..f14471c5fda7 100644 --- a/system/Config/Factories.php +++ b/system/Config/Factories.php @@ -267,6 +267,8 @@ public static function setOptions(string $component, array $values): array * Resets the static arrays, optionally just for one component * * @param string|null $component Lowercase, plural component name + * + * @return void */ public static function reset(?string $component = null) { @@ -290,6 +292,8 @@ public static function reset(?string $component = null) * * @param string $component Lowercase, plural component name * @param string $name The name of the instance + * + * @return void */ public static function injectMock(string $component, string $name, object $instance) { diff --git a/system/Config/ForeignCharacters.php b/system/Config/ForeignCharacters.php index f2e7cc57cabf..43db6f11a09f 100644 --- a/system/Config/ForeignCharacters.php +++ b/system/Config/ForeignCharacters.php @@ -18,6 +18,8 @@ class ForeignCharacters { /** * Without further ado, the list of foreign characters. + * + * @var array */ public $characterList = [ '/ä|æ|ǽ/' => 'ae', diff --git a/system/Config/Publisher.php b/system/Config/Publisher.php index 608e87afef8e..8f4e07b5c014 100644 --- a/system/Config/Publisher.php +++ b/system/Config/Publisher.php @@ -35,6 +35,8 @@ class Publisher extends BaseConfig /** * Disables Registrars to prevent modules from altering the restrictions. + * + * @return void */ final protected function registerProperties() { diff --git a/system/Config/View.php b/system/Config/View.php index 42d40faf879e..edeeeced1c98 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -33,6 +33,8 @@ class View extends BaseConfig * * To prevent potential abuse, all filters MUST be defined here * in order for them to be available for use within the Parser. + * + * @var array */ public $filters = []; @@ -40,6 +42,8 @@ class View extends BaseConfig * Parser Plugins provide a way to extend the functionality provided * by the core Parser by creating aliases that will be replaced with * any callable. Can be single or tag pair. + * + * @var array */ public $plugins = []; From 2d0fbffba019b35edfa367a6b4460a74cd49e269 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Wed, 2 Aug 2023 17:55:05 +0800 Subject: [PATCH 2/4] Dev: change the type. --- system/Config/ForeignCharacters.php | 2 +- system/Config/Publisher.php | 4 +--- system/Config/View.php | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/system/Config/ForeignCharacters.php b/system/Config/ForeignCharacters.php index 43db6f11a09f..3fac83dd29c2 100644 --- a/system/Config/ForeignCharacters.php +++ b/system/Config/ForeignCharacters.php @@ -19,7 +19,7 @@ class ForeignCharacters /** * Without further ado, the list of foreign characters. * - * @var array + * @var array */ public $characterList = [ '/ä|æ|ǽ/' => 'ae', diff --git a/system/Config/Publisher.php b/system/Config/Publisher.php index 8f4e07b5c014..fa04e24cd28f 100644 --- a/system/Config/Publisher.php +++ b/system/Config/Publisher.php @@ -35,10 +35,8 @@ class Publisher extends BaseConfig /** * Disables Registrars to prevent modules from altering the restrictions. - * - * @return void */ - final protected function registerProperties() + final protected function registerProperties(): void { } } diff --git a/system/Config/View.php b/system/Config/View.php index edeeeced1c98..e72e9157d186 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -34,7 +34,7 @@ class View extends BaseConfig * To prevent potential abuse, all filters MUST be defined here * in order for them to be available for use within the Parser. * - * @var array + * @var array */ public $filters = []; @@ -43,7 +43,7 @@ class View extends BaseConfig * by the core Parser by creating aliases that will be replaced with * any callable. Can be single or tag pair. * - * @var array + * @var array */ public $plugins = []; From 47f0f157b21f2c7d7b0862a549558e694a207d94 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Wed, 2 Aug 2023 18:06:17 +0800 Subject: [PATCH 3/4] dev: change the properties type. --- system/Config/View.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Config/View.php b/system/Config/View.php index e72e9157d186..cf5c77dd7cea 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -34,7 +34,7 @@ class View extends BaseConfig * To prevent potential abuse, all filters MUST be defined here * in order for them to be available for use within the Parser. * - * @var array + * @var array */ public $filters = []; @@ -43,7 +43,7 @@ class View extends BaseConfig * by the core Parser by creating aliases that will be replaced with * any callable. Can be single or tag pair. * - * @var array + * @var array */ public $plugins = []; From be62e2ed5f4865739ec9e93a66b57be6be15cf94 Mon Sep 17 00:00:00 2001 From: ping-yee <611077101@mail.nknu.edu.tw> Date: Fri, 4 Aug 2023 00:04:16 +0800 Subject: [PATCH 4/4] Dev: remove the useless comment and add some type for the properties. --- phpstan-baseline.php | 30 +++++++++++++++++++++++++++++ system/Config/ForeignCharacters.php | 2 +- system/Config/View.php | 12 ++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 58ade466d21c..cf5e2fe76b2d 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1,6 +1,16 @@ '#^PHPDoc type array of property Config\\\\View\\:\\:\\$filters is not covariant with PHPDoc type array\\ of overridden property CodeIgniter\\\\Config\\\\View\\:\\:\\$filters\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Config/View.php', +]; +$ignoreErrors[] = [ + 'message' => '#^PHPDoc type array of property Config\\\\View\\:\\:\\$plugins is not covariant with PHPDoc type array\\ of overridden property CodeIgniter\\\\Config\\\\View\\:\\:\\$plugins\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/app/Config/View.php', +]; $ignoreErrors[] = [ 'message' => '#^Parameter \\#1 \\$callback of function spl_autoload_register expects \\(callable\\(string\\)\\: void\\)\\|null, array\\{\\$this\\(CodeIgniter\\\\Autoloader\\\\Autoloader\\), \'loadClass\'\\} given\\.$#', 'count' => 1, @@ -316,6 +326,26 @@ 'count' => 1, 'path' => __DIR__ . '/system/ComposerScripts.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$coreFilters type has no signature specified for callable\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Config/View.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$corePlugins type has no signature specified for callable\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Config/View.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$filters type has no signature specified for callable\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Config/View.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$plugins type has no signature specified for callable\\.$#', + 'count' => 1, + 'path' => __DIR__ . '/system/Config/View.php', +]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Controller\\:\\:cachePage\\(\\) has no return type specified\\.$#', 'count' => 1, diff --git a/system/Config/ForeignCharacters.php b/system/Config/ForeignCharacters.php index 3fac83dd29c2..a8569f5419c5 100644 --- a/system/Config/ForeignCharacters.php +++ b/system/Config/ForeignCharacters.php @@ -17,7 +17,7 @@ class ForeignCharacters { /** - * Without further ado, the list of foreign characters. + * The list of foreign characters. * * @var array */ diff --git a/system/Config/View.php b/system/Config/View.php index cf5c77dd7cea..de4ed62b936a 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -34,7 +34,8 @@ class View extends BaseConfig * To prevent potential abuse, all filters MUST be defined here * in order for them to be available for use within the Parser. * - * @var array + * @var array + * @phpstan-var array */ public $filters = []; @@ -43,14 +44,16 @@ class View extends BaseConfig * by the core Parser by creating aliases that will be replaced with * any callable. Can be single or tag pair. * - * @var array + * @var array + * @phpstan-var array */ public $plugins = []; /** * Built-in View filters. * - * @var array + * @var array + * @phpstan-var array */ protected $coreFilters = [ 'abs' => '\abs', @@ -79,7 +82,8 @@ class View extends BaseConfig /** * Built-in View plugins. * - * @var array + * @var array + * @phpstan-var array */ protected $corePlugins = [ 'csp_script_nonce' => '\CodeIgniter\View\Plugins::cspScriptNonce',