From 426f6d95c8f96fe84e12b92646b19ae8a8405904 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 11 Sep 2026 20:48:18 +0200 Subject: [PATCH] Remove RenameDeprecatedMethodCallRector Too risky to infer replacements from @deprecated descriptions; explicit per-version rename rule registration is safer and predictable. Claude-Session: https://claude.ai/code/session_01JJoiy9Q76AadRMLSz6Xfj3 --- ...catedMethodCallReplacementResolverTest.php | 52 ------------ .../Fixture/rename_replaced_by.php.inc | 25 ------ .../Fixture/rename_see_tag.php.inc | 25 ------ .../Fixture/rename_static_call.php.inc | 25 ------ .../Fixture/rename_use_instead.php.inc | 25 ------ .../skip_magic_method_suggestion.php.inc | 11 --- .../Fixture/skip_no_suggestion.php.inc | 11 --- .../Fixture/skip_not_deprecated.php.inc | 10 --- .../RenameDeprecatedMethodCallRectorTest.php | 28 ------- .../Source/MagicMethodApiClient.php | 24 ------ .../Source/SomeApiClient.php | 58 ------------- .../config/configured_rule.php | 9 -- ...eprecatedMethodCallReplacementResolver.php | 78 ----------------- .../RenameDeprecatedMethodCallRector.php | 83 ------------------- 14 files changed, 464 deletions(-) delete mode 100644 rules-tests/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolverTest.php delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_replaced_by.php.inc delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_see_tag.php.inc delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_static_call.php.inc delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_use_instead.php.inc delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_magic_method_suggestion.php.inc delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_no_suggestion.php.inc delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_not_deprecated.php.inc delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/RenameDeprecatedMethodCallRectorTest.php delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Source/MagicMethodApiClient.php delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Source/SomeApiClient.php delete mode 100644 rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/config/configured_rule.php delete mode 100644 rules/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolver.php delete mode 100644 rules/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector.php diff --git a/rules-tests/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolverTest.php b/rules-tests/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolverTest.php deleted file mode 100644 index 7bdcf4b55fa..00000000000 --- a/rules-tests/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolverTest.php +++ /dev/null @@ -1,52 +0,0 @@ -deprecatedMethodCallReplacementResolver = $this->make(DeprecatedMethodCallReplacementResolver::class); - $this->reflectionProvider = $this->make(ReflectionProvider::class); - } - - #[DataProvider('provideData')] - public function test(string $methodName, ?string $expectedReplacement): void - { - $classReflection = $this->reflectionProvider->getClass(DeprecatedMethodsClient::class); - $extendedMethodReflection = $classReflection->getNativeMethod($methodName); - - $resolvedReplacement = $this->deprecatedMethodCallReplacementResolver->resolve($extendedMethodReflection); - $this->assertSame($expectedReplacement, $resolvedReplacement); - } - - /** - * @return Iterator - */ - public static function provideData(): Iterator - { - yield 'use ...() instead' => ['getData', 'fetchData']; - yield 'replaced by ...()' => ['loadData', 'fetchData']; - yield '{@see ...()}' => ['readData', 'fetchData']; - yield 'static use ...() instead' => ['makeOld', 'make']; - yield 'deprecated without method suggestion' => ['legacyData', null]; - yield 'suggested method does not exist' => ['vanishedData', null]; - yield 'suggested method is itself deprecated' => ['deadEndData', null]; - yield 'not deprecated at all' => ['fetchData', null]; - } -} diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_replaced_by.php.inc b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_replaced_by.php.inc deleted file mode 100644 index ccace790ff0..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_replaced_by.php.inc +++ /dev/null @@ -1,25 +0,0 @@ -loadData(); -} - -?> ------ -fetchData(); -} - -?> diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_see_tag.php.inc b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_see_tag.php.inc deleted file mode 100644 index b810181fc02..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_see_tag.php.inc +++ /dev/null @@ -1,25 +0,0 @@ -readData(); -} - -?> ------ -fetchData(); -} - -?> diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_static_call.php.inc b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_static_call.php.inc deleted file mode 100644 index ab615b8989f..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_static_call.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - ------ - diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_use_instead.php.inc b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_use_instead.php.inc deleted file mode 100644 index 147e12b2dd3..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/rename_use_instead.php.inc +++ /dev/null @@ -1,25 +0,0 @@ -getData(); -} - -?> ------ -fetchData(); -} - -?> diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_magic_method_suggestion.php.inc b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_magic_method_suggestion.php.inc deleted file mode 100644 index c951c5b6c02..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_magic_method_suggestion.php.inc +++ /dev/null @@ -1,11 +0,0 @@ -getData(); -} diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_no_suggestion.php.inc b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_no_suggestion.php.inc deleted file mode 100644 index fa30f86cb71..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_no_suggestion.php.inc +++ /dev/null @@ -1,11 +0,0 @@ -legacyData(); -} diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_not_deprecated.php.inc b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_not_deprecated.php.inc deleted file mode 100644 index 0c4d9f5a3b4..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Fixture/skip_not_deprecated.php.inc +++ /dev/null @@ -1,10 +0,0 @@ -fetchData(); -} diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/RenameDeprecatedMethodCallRectorTest.php b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/RenameDeprecatedMethodCallRectorTest.php deleted file mode 100644 index c2197f31579..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/RenameDeprecatedMethodCallRectorTest.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/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Source/MagicMethodApiClient.php b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Source/MagicMethodApiClient.php deleted file mode 100644 index 4fd447751f6..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/Source/MagicMethodApiClient.php +++ /dev/null @@ -1,24 +0,0 @@ -fetchData(); - } - - /** - * @deprecated replaced by fetchData() - */ - public function loadData(): array - { - return $this->fetchData(); - } - - /** - * @deprecated {@see fetchData()} - */ - public function readData(): array - { - return $this->fetchData(); - } - - /** - * @deprecated since 2.0, use the repository layer instead - */ - public function legacyData(): array - { - return $this->fetchData(); - } - - public function fetchData(): array - { - return []; - } - - /** - * @deprecated use make() instead - */ - public static function makeOld(): self - { - return new self(); - } - - public static function make(): self - { - return new self(); - } -} diff --git a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/config/configured_rule.php b/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/config/configured_rule.php deleted file mode 100644 index 65d1ee0f8e5..00000000000 --- a/rules-tests/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector/config/configured_rule.php +++ /dev/null @@ -1,9 +0,0 @@ -withRules([RenameDeprecatedMethodCallRector::class]); diff --git a/rules/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolver.php b/rules/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolver.php deleted file mode 100644 index 2b9cb34da78..00000000000 --- a/rules/Renaming/NodeAnalyzer/DeprecatedMethodCallReplacementResolver.php +++ /dev/null @@ -1,78 +0,0 @@ -\w+)\(\)#i'; - - /** - * Resolves a non-deprecated replacement method name suggested by the "@deprecated" docblock - * of the given method, or null when there is no usable suggestion. - */ - public function resolve(MethodReflection $methodReflection): ?string - { - if (! $methodReflection->isDeprecated()->yes()) { - return null; - } - - $newMethodName = $this->matchNewMethodName($methodReflection->getDeprecatedDescription()); - if ($newMethodName === null) { - return null; - } - - // already the suggested name? nothing to do - if (strtolower($methodReflection->getName()) === strtolower($newMethodName)) { - return null; - } - - if (! $this->isExistingNonDeprecatedMethod($methodReflection->getDeclaringClass(), $newMethodName)) { - return null; - } - - return $newMethodName; - } - - private function matchNewMethodName(?string $deprecatedDescription): ?string - { - if ($deprecatedDescription === null || $deprecatedDescription === '') { - return null; - } - - $match = Strings::match($deprecatedDescription, self::RENAME_SUGGESTION_REGEX); - if ($match === null) { - return null; - } - - return $match['method']; - } - - private function isExistingNonDeprecatedMethod(ClassReflection $classReflection, string $newMethodName): bool - { - if (! $classReflection->hasNativeMethod($newMethodName)) { - return false; - } - - // do not rename onto another deprecated method, to avoid suggesting a dead end - $extendedMethodReflection = $classReflection->getNativeMethod($newMethodName); - return ! $extendedMethodReflection->isDeprecated() - ->yes(); - } -} diff --git a/rules/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector.php b/rules/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector.php deleted file mode 100644 index d96d067dc4f..00000000000 --- a/rules/Renaming/Rector/MethodCall/RenameDeprecatedMethodCallRector.php +++ /dev/null @@ -1,83 +0,0 @@ -oldMethod(); -CODE_SAMPLE - , - <<<'CODE_SAMPLE' -$someObject->newMethod(); -CODE_SAMPLE - ), - ] - ); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [MethodCall::class, StaticCall::class]; - } - - /** - * @param MethodCall|StaticCall $node - */ - public function refactor(Node $node): ?Node - { - if ($node->isFirstClassCallable()) { - return null; - } - - if ($this->getName($node->name) === null) { - return null; - } - - $methodReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node); - - if (! $methodReflection instanceof MethodReflection) { - return null; - } - - $newMethodName = $this->deprecatedMethodCallReplacementResolver->resolve($methodReflection); - if ($newMethodName === null) { - return null; - } - - $node->name = new Identifier($newMethodName); - - return $node; - } -}