From a1c6c9e998297c24ed22733c786038657aaff50b Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Thu, 6 Mar 2025 14:33:30 +0300 Subject: [PATCH 1/5] refactor: Update return types `ReflectionHelper` --- system/Test/ReflectionHelper.php | 3 +-- tests/system/Commands/Utilities/ConfigCheckTest.php | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/system/Test/ReflectionHelper.php b/system/Test/ReflectionHelper.php index 988fe949004c..47e85f4a8903 100644 --- a/system/Test/ReflectionHelper.php +++ b/system/Test/ReflectionHelper.php @@ -31,8 +31,7 @@ trait ReflectionHelper * @param object|string $obj object or class name * @param string $method method name * - * @return Closure - * @phpstan-return Closure(mixed ...$args): mixed + * @return Closure(mixed ...$args): mixed * * @throws ReflectionException */ diff --git a/tests/system/Commands/Utilities/ConfigCheckTest.php b/tests/system/Commands/Utilities/ConfigCheckTest.php index e49a8170ec08..dcd001b0c323 100644 --- a/tests/system/Commands/Utilities/ConfigCheckTest.php +++ b/tests/system/Commands/Utilities/ConfigCheckTest.php @@ -89,7 +89,9 @@ public function testCommandConfigCheckNonexistentClass(): void public function testConfigCheckWithKintEnabledUsesKintD(): void { - /** @var Closure(object): string $command */ + /** + * @var Closure(mixed...): string + */ $command = $this->getPrivateMethodInvoker( new ConfigCheck(service('logger'), service('commands')), 'getKintD', @@ -105,7 +107,9 @@ public function testConfigCheckWithKintEnabledUsesKintD(): void public function testConfigCheckWithKintDisabledUsesVarDump(): void { - /** @var Closure(object): string $command */ + /** + * @var Closure(mixed...): string + */ $command = $this->getPrivateMethodInvoker( new ConfigCheck(service('logger'), service('commands')), 'getVarDump', From f729a7c30f52a6b536496fad89150bcee96e9968 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Thu, 6 Mar 2025 14:35:26 +0300 Subject: [PATCH 2/5] refactor: Update types in RedisHandler::deleteMatching() --- system/Cache/Handlers/RedisHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Cache/Handlers/RedisHandler.php b/system/Cache/Handlers/RedisHandler.php index 6cd43506bdb5..80c21e8559e8 100644 --- a/system/Cache/Handlers/RedisHandler.php +++ b/system/Cache/Handlers/RedisHandler.php @@ -181,7 +181,7 @@ public function deleteMatching(string $pattern) $iterator = null; do { - /** @var false|list|Redis $keys */ + /** @var false|list $keys */ $keys = $this->redis->scan($iterator, $pattern); if (is_array($keys)) { From 98239223b4d030d75cd2673bd76a5f74297df1da Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Thu, 6 Mar 2025 14:36:24 +0300 Subject: [PATCH 3/5] refactor: Remove unnecessary hints --- system/Commands/Generators/MigrationGenerator.php | 5 +---- system/HTTP/CURLRequest.php | 4 +--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/system/Commands/Generators/MigrationGenerator.php b/system/Commands/Generators/MigrationGenerator.php index b7d7d585e945..b5e64ec1bce1 100644 --- a/system/Commands/Generators/MigrationGenerator.php +++ b/system/Commands/Generators/MigrationGenerator.php @@ -112,10 +112,7 @@ protected function prepare(string $class): string $data['DBGroup'] = is_string($DBGroup) ? $DBGroup : 'default'; $data['DBDriver'] = config(Database::class)->{$data['DBGroup']}['DBDriver']; - /** @var SessionConfig|null $session */ - $session = config(SessionConfig::class); - - $data['matchIP'] = $session->matchIP; + $data['matchIP'] = config(SessionConfig::class)->matchIP; } return $this->parseTemplate($class, [], [], $data); diff --git a/system/HTTP/CURLRequest.php b/system/HTTP/CURLRequest.php index 742da9f18d08..8a21d77262a0 100644 --- a/system/HTTP/CURLRequest.php +++ b/system/HTTP/CURLRequest.php @@ -125,9 +125,7 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response $this->baseURI = $uri->useRawQueryString(); $this->defaultOptions = $options; - /** @var ConfigCURLRequest|null $configCURLRequest */ - $configCURLRequest = config(ConfigCURLRequest::class); - $this->shareOptions = $configCURLRequest->shareOptions ?? true; + $this->shareOptions = config(ConfigCURLRequest::class)->shareOptions ?? true; $this->config = $this->defaultConfig; $this->parseOptions($options); From 7fd06900ca33dd55fc4d7b81dd67ad95b50cebb5 Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Thu, 6 Mar 2025 14:37:07 +0300 Subject: [PATCH 4/5] refactor: TimeTrait::$timezone can be a string --- system/I18n/TimeTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/I18n/TimeTrait.php b/system/I18n/TimeTrait.php index 5e908bef5c2e..42278c960c43 100644 --- a/system/I18n/TimeTrait.php +++ b/system/I18n/TimeTrait.php @@ -32,7 +32,7 @@ trait TimeTrait { /** - * @var DateTimeZone + * @var DateTimeZone|string */ protected $timezone; From e2f8c3cc81cfa2d14df7d3c9ea6bc50b9351c6ab Mon Sep 17 00:00:00 2001 From: neznaika0 Date: Thu, 6 Mar 2025 14:37:47 +0300 Subject: [PATCH 5/5] refactor: Refresh phpstan baseline --- utils/phpstan-baseline/varTag.type.neon | 32 +------------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/utils/phpstan-baseline/varTag.type.neon b/utils/phpstan-baseline/varTag.type.neon index 8edeb6f38113..4be1089ace00 100644 --- a/utils/phpstan-baseline/varTag.type.neon +++ b/utils/phpstan-baseline/varTag.type.neon @@ -1,37 +1,7 @@ -# total 9 errors +# total 2 errors parameters: ignoreErrors: - - - message: '#^PHPDoc tag @var with type list\\|Redis\|false is not subtype of type array\\|false\.$#' - count: 1 - path: ../../system/Cache/Handlers/RedisHandler.php - - - - message: '#^PHPDoc tag @var with type Config\\Session\|null is not subtype of type Config\\Session\.$#' - count: 1 - path: ../../system/Commands/Generators/MigrationGenerator.php - - - - message: '#^PHPDoc tag @var with type Config\\CURLRequest\|null is not subtype of type Config\\CURLRequest\.$#' - count: 1 - path: ../../system/HTTP/CURLRequest.php - - - - message: '#^PHPDoc tag @var with type string is not subtype of type DateTimeZone\.$#' - count: 1 - path: ../../system/I18n/Time.php - - - - message: '#^PHPDoc tag @var with type string is not subtype of type DateTimeZone\.$#' - count: 1 - path: ../../system/I18n/TimeLegacy.php - - - - message: '#^PHPDoc tag @var with type Closure\(object\)\: string is not subtype of type Closure\(mixed \.\.\.\)\: mixed\.$#' - count: 2 - path: ../../tests/system/Commands/Utilities/ConfigCheckTest.php - - message: '#^PHPDoc tag @var with type Tests\\Support\\Entity\\UserWithCasts is not subtype of type list\\|null\.$#' count: 1