From e8e2c9f0c999b6cd17f219e54ffd994f104e6d21 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Thu, 12 Dec 2024 20:54:15 +0800 Subject: [PATCH] Fix rector changes --- rector.php | 2 -- system/Session/Session.php | 2 +- tests/system/Debug/ExceptionsTest.php | 10 +++------- utils/phpstan-baseline/function.resultUnused.neon | 8 -------- utils/phpstan-baseline/loader.neon | 1 - .../RemoveErrorSuppressInTryCatchStmtsRector.php | 3 ++- .../Rector/UnderscoreToCamelCaseVariableNameRector.php | 2 +- 7 files changed, 7 insertions(+), 21 deletions(-) delete mode 100644 utils/phpstan-baseline/function.resultUnused.neon diff --git a/rector.php b/rector.php index 1e6548c047ca..e7c98746eb86 100644 --- a/rector.php +++ b/rector.php @@ -36,7 +36,6 @@ use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; use Rector\Php70\Rector\FuncCall\RandomFunctionRector; use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; -use Rector\Php80\Rector\FunctionLike\MixedTypeRector; use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector; use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; use Rector\PHPUnit\Set\PHPUnitSetList; @@ -152,7 +151,6 @@ __DIR__ . '/system/Security/Security.php', __DIR__ . '/system/Session/Session.php', ], - MixedTypeRector::class, ReturnNeverTypeRector::class => [ __DIR__ . '/system/Cache/Handlers/BaseHandler.php', diff --git a/system/Session/Session.php b/system/Session/Session.php index b522f63af5f2..60e4dbef4101 100644 --- a/system/Session/Session.php +++ b/system/Session/Session.php @@ -248,7 +248,7 @@ public function start() if (! isset($_SESSION['__ci_last_regenerate'])) { $_SESSION['__ci_last_regenerate'] = Time::now()->getTimestamp(); } elseif ($_SESSION['__ci_last_regenerate'] < (Time::now()->getTimestamp() - $regenerateTime)) { - $this->regenerate((bool) $this->config->regenerateDestroy); + $this->regenerate($this->config->regenerateDestroy); } } // Another work-around ... PHP doesn't seem to send the session cookie diff --git a/tests/system/Debug/ExceptionsTest.php b/tests/system/Debug/ExceptionsTest.php index bb76c16b290c..b8279fb8e190 100644 --- a/tests/system/Debug/ExceptionsTest.php +++ b/tests/system/Debug/ExceptionsTest.php @@ -66,14 +66,10 @@ public function testDeprecationsOnPhp81DoNotThrow(): void $this->exception = new Exceptions($config); $this->exception->initialize(); - // this is only needed for IDEs not to complain that strlen does not accept explicit null - $maybeNull = PHP_VERSION_ID >= 80100 ? null : 'random string'; - try { - // We test DEPRECATED error, so cannot set `declare(strict_types=1)` in this file. - strlen($maybeNull); - $this->assertLogContains('error', '[DEPRECATED] strlen(): '); - } catch (ErrorException $e) { + $result = str_contains('foobar', null); // @phpstan-ignore argument.type (Needed for testing) + $this->assertLogContains('error', '[DEPRECATED] str_contains(): '); + } catch (ErrorException) { $this->fail('The catch block should not be reached.'); } finally { restore_error_handler(); diff --git a/utils/phpstan-baseline/function.resultUnused.neon b/utils/phpstan-baseline/function.resultUnused.neon deleted file mode 100644 index 34e011c78a08..000000000000 --- a/utils/phpstan-baseline/function.resultUnused.neon +++ /dev/null @@ -1,8 +0,0 @@ -# total 1 error - -parameters: - ignoreErrors: - - - message: '#^Call to function strlen\(\) on a separate line has no effect\.$#' - count: 1 - path: ../../tests/system/Debug/ExceptionsTest.php diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 10943c597f35..cc50a8469370 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -26,7 +26,6 @@ includes: - function.alreadyNarrowedType.neon - function.inner.neon - function.notFound.neon - - function.resultUnused.neon - generator.returnType.neon - generator.valueType.neon - greaterOrEqual.invalid.neon diff --git a/utils/src/Rector/RemoveErrorSuppressInTryCatchStmtsRector.php b/utils/src/Rector/RemoveErrorSuppressInTryCatchStmtsRector.php index feb697774f6f..1d36c5794739 100644 --- a/utils/src/Rector/RemoveErrorSuppressInTryCatchStmtsRector.php +++ b/utils/src/Rector/RemoveErrorSuppressInTryCatchStmtsRector.php @@ -14,6 +14,7 @@ namespace Utils\Rector; use PhpParser\Node; +use PhpParser\Node\Expr; use PhpParser\Node\Expr\ErrorSuppress; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Function_; @@ -60,7 +61,7 @@ public function refactor(Node $node): ?Node $this->traverseNodesWithCallable( $node->stmts, - static function (Node $subNode) use (&$hasChanged) { + static function (Node $subNode) use (&$hasChanged): int|Expr|null { if ($subNode instanceof Class_ || $subNode instanceof Function_) { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } diff --git a/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php b/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php index 25d09fadacb6..1e1469c7f615 100644 --- a/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php +++ b/utils/src/Rector/UnderscoreToCamelCaseVariableNameRector.php @@ -169,7 +169,7 @@ private function updateDocblock(string $variableName, string $camelCaseName, ?Fu } $docComment = $functionLike->getDocComment(); - if ($docComment === null) { + if (! $docComment instanceof Doc) { return; }