From 8a6c93a38f299294bc6fdcf160287c75e7379f57 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 20 Oct 2025 19:47:27 +0200 Subject: [PATCH] [PHP 8.5] replace WrapFuncCallWithPhpVersionIdCheckerRector with RemoveFuncCallRector removal --- config/set/php85.php | 17 +- .../Fixture/different_function.php.inc | 8 - .../skip_already_if_version_check.php.inc | 12 -- ...version_check_with_function_exists.php.inc | 12 -- .../skip_func_call_in_assignment.php.inc | 7 - .../skip_func_call_in_condition.php.inc | 9 - .../Fixture/wrapped_function.php.inc | 21 -- ...cCallWithPhpVersionIdCheckerRectorTest.php | 28 --- .../config/configured_rule.php | 13 -- .../Rector/FuncCall/RemoveFuncCallRector.php | 2 +- ...pFuncCallWithPhpVersionIdCheckerRector.php | 185 ------------------ .../WrapFuncCallWithPhpVersionIdChecker.php | 24 --- 12 files changed, 6 insertions(+), 332 deletions(-) delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/different_function.php.inc delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check.php.inc delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check_with_function_exists.php.inc delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_assignment.php.inc delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_condition.php.inc delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/wrapped_function.php.inc delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/WrapFuncCallWithPhpVersionIdCheckerRectorTest.php delete mode 100644 rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/config/configured_rule.php delete mode 100644 rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php delete mode 100644 rules/Transform/ValueObject/WrapFuncCallWithPhpVersionIdChecker.php diff --git a/config/set/php85.php b/config/set/php85.php index 33e526c3bf2..9e4f1e477f2 100644 --- a/config/set/php85.php +++ b/config/set/php85.php @@ -19,6 +19,7 @@ use Rector\Php85\Rector\ShellExec\ShellExecFunctionCallOverBackticksRector; use Rector\Php85\Rector\Switch_\ColonAfterSwitchCaseRector; use Rector\Removing\Rector\FuncCall\RemoveFuncCallArgRector; +use Rector\Removing\Rector\FuncCall\RemoveFuncCallRector; use Rector\Removing\ValueObject\RemoveFuncCallArg; use Rector\Renaming\Rector\Cast\RenameCastRector; use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector; @@ -28,8 +29,6 @@ use Rector\Renaming\ValueObject\MethodCallRename; use Rector\Renaming\ValueObject\RenameCast; use Rector\Renaming\ValueObject\RenameClassAndConstFetch; -use Rector\Transform\Rector\FuncCall\WrapFuncCallWithPhpVersionIdCheckerRector; -use Rector\Transform\ValueObject\WrapFuncCallWithPhpVersionIdChecker; return static function (RectorConfig $rectorConfig): void { $rectorConfig->rules( @@ -199,16 +198,10 @@ ); // https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_no-op_functions_from_the_resource_to_object_conversion - $rectorConfig->ruleWithConfiguration( - WrapFuncCallWithPhpVersionIdCheckerRector::class, - [ - new WrapFuncCallWithPhpVersionIdChecker('curl_close', 80500), - new WrapFuncCallWithPhpVersionIdChecker('curl_share_close', 80500), - new WrapFuncCallWithPhpVersionIdChecker('finfo_close', 80500), - new WrapFuncCallWithPhpVersionIdChecker('imagedestroy', 80500), - new WrapFuncCallWithPhpVersionIdChecker('xml_parser_free', 80500), - ] - ); + // these function have no effect when use + $rectorConfig->ruleWithConfiguration(RemoveFuncCallRector::class, [ + 'curl_close', 'curl_share_close', 'finfo_close', 'imagedestroy', 'xml_parser_free', + ]); // https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_filter_default_constant $rectorConfig->ruleWithConfiguration(RenameConstantRector::class, [ diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/different_function.php.inc b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/different_function.php.inc deleted file mode 100644 index e8ad4d4693d..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/different_function.php.inc +++ /dev/null @@ -1,8 +0,0 @@ - diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check.php.inc b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check.php.inc deleted file mode 100644 index 0e9f813fd62..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check.php.inc +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check_with_function_exists.php.inc b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check_with_function_exists.php.inc deleted file mode 100644 index 6bad9d59da8..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_already_if_version_check_with_function_exists.php.inc +++ /dev/null @@ -1,12 +0,0 @@ - diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_assignment.php.inc b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_assignment.php.inc deleted file mode 100644 index a09f15bdd31..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_assignment.php.inc +++ /dev/null @@ -1,7 +0,0 @@ - diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_condition.php.inc b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_condition.php.inc deleted file mode 100644 index 241bcbe23bb..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/skip_func_call_in_condition.php.inc +++ /dev/null @@ -1,9 +0,0 @@ - diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/wrapped_function.php.inc b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/wrapped_function.php.inc deleted file mode 100644 index 52d509c0a10..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/Fixture/wrapped_function.php.inc +++ /dev/null @@ -1,21 +0,0 @@ - ------ - diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/WrapFuncCallWithPhpVersionIdCheckerRectorTest.php b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/WrapFuncCallWithPhpVersionIdCheckerRectorTest.php deleted file mode 100644 index 03384cc4e38..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/WrapFuncCallWithPhpVersionIdCheckerRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/config/configured_rule.php b/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/config/configured_rule.php deleted file mode 100644 index 0a49f668967..00000000000 --- a/rules-tests/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector/config/configured_rule.php +++ /dev/null @@ -1,13 +0,0 @@ -withConfiguredRule( - WrapFuncCallWithPhpVersionIdCheckerRector::class, - [new WrapFuncCallWithPhpVersionIdChecker('no_op_function', 80500)] - ); diff --git a/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php b/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php index 4ecaaa90e5f..3386fee6d13 100644 --- a/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php +++ b/rules/Removing/Rector/FuncCall/RemoveFuncCallRector.php @@ -26,7 +26,7 @@ final class RemoveFuncCallRector extends AbstractRector implements ConfigurableR public function getRuleDefinition(): RuleDefinition { - return new RuleDefinition('Remove function', [ + return new RuleDefinition('Remove defined function calls', [ new ConfiguredCodeSample( <<<'CODE_SAMPLE' $x = 'something'; diff --git a/rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php b/rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php deleted file mode 100644 index 694a7da036e..00000000000 --- a/rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php +++ /dev/null @@ -1,185 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [StmtsAwareInterface::class]; - } - - /** - * @param StmtsAwareInterface $node - * @return null|Node|NodeVisitor::DONT_TRAVERSE_CHILDREN - */ - public function refactor(Node $node): null|Node|int - { - if ($node->stmts === null) { - return null; - } - - if ($this->isWrappedFuncCall($node)) { - return NodeVisitor::DONT_TRAVERSE_CHILDREN; - } - - $hasChanged = false; - foreach ($node->stmts as $key => $stmt) { - if (! $stmt instanceof Expression) { - continue; - } - - if (! $stmt->expr instanceof FuncCall) { - continue; - } - - $funcCall = $stmt->expr; - - foreach ($this->wrapFuncCallWithPhpVersionIdCheckers as $wrapFuncCallWithPhpVersionIdChecker) { - if ($this->getName($funcCall) !== $wrapFuncCallWithPhpVersionIdChecker->getFunctionName()) { - continue; - } - - $phpVersionIdConst = new ConstFetch(new Name('PHP_VERSION_ID')); - $if = new If_(new BooleanAnd( - new FuncCall(new Name('function_exists'), [new Arg(new String_( - $wrapFuncCallWithPhpVersionIdChecker->getFunctionName() - ))]), - new Smaller($phpVersionIdConst, new Int_($wrapFuncCallWithPhpVersionIdChecker->getPhpVersionId())), - )); - $if->stmts = [$stmt]; - - $node->stmts[$key] = $if; - - $hasChanged = true; - } - } - - if ($hasChanged) { - return $node; - } - - return null; - } - - public function configure(array $configuration): void - { - Assert::allIsInstanceOf($configuration, WrapFuncCallWithPhpVersionIdChecker::class); - - $this->wrapFuncCallWithPhpVersionIdCheckers = $configuration; - } - - private function isWrappedFuncCall(StmtsAwareInterface $stmtsAware): bool - { - if (! $stmtsAware instanceof If_) { - return false; - } - - $phpVersionId = $this->getPhpVersionId($stmtsAware->cond); - if (! $phpVersionId instanceof Int_) { - return false; - } - - if (count($stmtsAware->stmts) !== 1) { - return false; - } - - $childStmt = $stmtsAware->stmts[0]; - - if (! $childStmt instanceof Expression || ! $childStmt->expr instanceof FuncCall) { - return false; - } - - foreach ($this->wrapFuncCallWithPhpVersionIdCheckers as $wrapFuncCallWithPhpVersionIdChecker) { - if ($this->getName($childStmt->expr) !== $wrapFuncCallWithPhpVersionIdChecker->getFunctionName()) { - continue; - } - - if ($phpVersionId->value !== $wrapFuncCallWithPhpVersionIdChecker->getPhpVersionId()) { - continue; - } - - return true; - } - - return false; - } - - private function getPhpVersionId(Expr $expr): ?Int_ - { - if ($expr instanceof BooleanAnd) { - return $this->getPhpVersionId($expr->left) ?? $this->getPhpVersionId($expr->right); - } - - if (! $expr instanceof Smaller) { - return null; - } - - if (! $expr->left instanceof ConstFetch || ! $this->isName($expr->left->name, 'PHP_VERSION_ID')) { - return null; - } - - if (! $expr->right instanceof Int_) { - return null; - } - - return $expr->right; - } -} diff --git a/rules/Transform/ValueObject/WrapFuncCallWithPhpVersionIdChecker.php b/rules/Transform/ValueObject/WrapFuncCallWithPhpVersionIdChecker.php deleted file mode 100644 index cc100a6ccec..00000000000 --- a/rules/Transform/ValueObject/WrapFuncCallWithPhpVersionIdChecker.php +++ /dev/null @@ -1,24 +0,0 @@ -functionName; - } - - public function getPhpVersionId(): int - { - return $this->phpVersionId; - } -}