66
77use PhpParser \Node ;
88use PhpParser \Node \Expr \StaticCall ;
9- use PhpParser \Node \Identifier ;
10- use PhpParser \Node \Name \FullyQualified ;
9+ use Rector \Configuration \Deprecation \Contract \DeprecatedInterface ;
1110use Rector \Contract \Rector \ConfigurableRectorInterface ;
11+ use Rector \Exception \ShouldNotHappenException ;
1212use Rector \Rector \AbstractRector ;
1313use Rector \Renaming \ValueObject \RenameStaticMethod ;
1414use Rector \RuleDoc \CodeSample \ConfiguredCodeSample ;
1515use Rector \RuleDoc \RuleDefinition ;
16- use Webmozart \Assert \Assert ;
1716
1817/**
19- * @see \Rector\Tests\Renaming\Rector\StaticCall\RenameStaticMethodRector\RenameStaticMethodRectorTest
18+ * @deprecated This rule is deprecated, as too niche, never used and needs project context. Write a custom rule for the exact project case instead.
2019 */
21- final class RenameStaticMethodRector extends AbstractRector implements ConfigurableRectorInterface
20+ final class RenameStaticMethodRector extends AbstractRector implements ConfigurableRectorInterface, DeprecatedInterface
2221{
23- /**
24- * @var array<string, RenameStaticMethod[]>
25- */
26- private array $ staticMethodRenamesByOldMethod = [];
27-
2822 public function getRuleDefinition (): RuleDefinition
2923 {
3024 return new RuleDefinition ('Turn method names to new ones ' , [
@@ -49,44 +43,16 @@ public function getNodeTypes(): array
4943 */
5044 public function refactor (Node $ node ): ?Node
5145 {
52- $ methodName = $ this ->getName ($ node ->name );
53- if ($ methodName === null ) {
54- return null ;
55- }
56-
57- foreach ($ this ->staticMethodRenamesByOldMethod [strtolower ($ methodName )] ?? [] as $ staticMethodRename ) {
58- if (! $ this ->isObjectType ($ node ->class , $ staticMethodRename ->getOldObjectType ())) {
59- continue ;
60- }
61-
62- return $ this ->rename ($ node , $ staticMethodRename );
63- }
64-
65- return null ;
46+ throw new ShouldNotHappenException (sprintf (
47+ '"%s" rule is deprecated, as too niche and part of no set; write a custom rule for the exact project case instead ' ,
48+ self ::class
49+ ));
6650 }
6751
6852 /**
6953 * @param mixed[] $configuration
7054 */
7155 public function configure (array $ configuration ): void
7256 {
73- Assert::allIsAOf ($ configuration , RenameStaticMethod::class);
74-
75- // bucket by lowercased old method name (method names are case-insensitive)
76- $ this ->staticMethodRenamesByOldMethod = [];
77- foreach ($ configuration as $ staticMethodRename ) {
78- $ this ->staticMethodRenamesByOldMethod [strtolower ($ staticMethodRename ->getOldMethod ())][] = $ staticMethodRename ;
79- }
80- }
81-
82- private function rename (StaticCall $ staticCall , RenameStaticMethod $ renameStaticMethod ): StaticCall
83- {
84- $ staticCall ->name = new Identifier ($ renameStaticMethod ->getNewMethod ());
85-
86- if ($ renameStaticMethod ->hasClassChanged ()) {
87- $ staticCall ->class = new FullyQualified ($ renameStaticMethod ->getNewClass ());
88- }
89-
90- return $ staticCall ;
9157 }
9258}
0 commit comments