66
77use PhpParser \Node ;
88use PhpParser \Node \Expr \New_ ;
9- use Rector \Contract \Rector \ConfigurableRectorInterface ;
9+ use Rector \Configuration \Deprecation \Contract \DeprecatedInterface ;
10+ use Rector \Exception \ShouldNotHappenException ;
1011use Rector \Rector \AbstractRector ;
11- use Rector \RuleDoc \CodeSample \ConfiguredCodeSample ;
12+ use Rector \RuleDoc \CodeSample \CodeSample ;
1213use Rector \RuleDoc \RuleDefinition ;
13- use Rector \Transform \ValueObject \NewToStaticCall ;
14- use Webmozart \Assert \Assert ;
1514
1615/**
17- * @see \Rector\Tests\Transform\Rector\New_\NewToStaticCallRector\NewToStaticCallRectorTest
16+ * @deprecated This rule is deprecated, as too niche, never used, and requires careful context to pick the correct static call. Write a custom rule for the exact project case instead.
1817 */
19- final class NewToStaticCallRector extends AbstractRector implements ConfigurableRectorInterface
18+ final class NewToStaticCallRector extends AbstractRector implements DeprecatedInterface
2019{
21- /**
22- * @var NewToStaticCall[]
23- */
24- private array $ typeToStaticCalls = [];
25-
2620 public function getRuleDefinition (): RuleDefinition
2721 {
2822 return new RuleDefinition ('Change new Object to static call ' , [
29- new ConfiguredCodeSample (
23+ new CodeSample (
3024 <<<'CODE_SAMPLE'
3125class SomeClass
3226{
@@ -46,8 +40,6 @@ public function run()
4640 }
4741}
4842CODE_SAMPLE
49- ,
50- [new NewToStaticCall ('Cookie ' , 'Cookie ' , 'create ' )]
5143 ),
5244 ]);
5345 }
@@ -65,28 +57,9 @@ public function getNodeTypes(): array
6557 */
6658 public function refactor (Node $ node ): ?Node
6759 {
68- foreach ($ this ->typeToStaticCalls as $ typeToStaticCall ) {
69- if (! $ this ->isObjectType ($ node ->class , $ typeToStaticCall ->getObjectType ())) {
70- continue ;
71- }
72-
73- return $ this ->nodeFactory ->createStaticCall (
74- $ typeToStaticCall ->getStaticCallClass (),
75- $ typeToStaticCall ->getStaticCallMethod (),
76- $ node ->args
77- );
78- }
79-
80- return null ;
81- }
82-
83- /**
84- * @param mixed[] $configuration
85- */
86- public function configure (array $ configuration ): void
87- {
88- Assert ::allIsAOf ($ configuration , NewToStaticCall::class);
89-
90- $ this ->typeToStaticCalls = $ configuration ;
60+ throw new ShouldNotHappenException (sprintf (
61+ '"%s" rule is deprecated, as too niche and never used. Write a custom rule for the exact project case instead ' ,
62+ self ::class
63+ ));
9164 }
9265}
0 commit comments