|
5 | 5 | namespace Rector\Symfony\Symfony42\Rector\MethodCall;
|
6 | 6 |
|
7 | 7 | use PhpParser\Node;
|
8 |
| -use PhpParser\Node\Expr\ClassConstFetch; |
9 |
| -use PhpParser\Node\Expr\MethodCall; |
10 | 8 | use PhpParser\Node\Stmt\Class_;
|
11 |
| -use PHPStan\Type\ObjectType; |
12 | 9 | use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
|
13 |
| -use Rector\NodeManipulator\ClassDependencyManipulator; |
14 |
| -use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; |
15 |
| -use Rector\PostRector\ValueObject\PropertyMetadata; |
| 10 | +use Rector\Exception\ShouldNotHappenException; |
16 | 11 | use Rector\Rector\AbstractRector;
|
17 |
| -use Rector\Symfony\DependencyInjection\NodeDecorator\CommandConstructorDecorator; |
18 |
| -use Rector\Symfony\NodeAnalyzer\DependencyInjectionMethodCallAnalyzer; |
19 | 12 | use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
20 | 13 | use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
21 | 14 |
|
|
26 | 19 | */
|
27 | 20 | final class ContainerGetToConstructorInjectionRector extends AbstractRector implements DeprecatedInterface
|
28 | 21 | {
|
29 |
| - public function __construct( |
30 |
| - private readonly DependencyInjectionMethodCallAnalyzer $dependencyInjectionMethodCallAnalyzer, |
31 |
| - private readonly TestsNodeAnalyzer $testsNodeAnalyzer, |
32 |
| - private readonly ClassDependencyManipulator $classDependencyManipulator, |
33 |
| - private readonly CommandConstructorDecorator $commandConstructorDecorator, |
34 |
| - ) { |
35 |
| - } |
36 |
| - |
37 | 22 | public function getRuleDefinition(): RuleDefinition
|
38 | 23 | {
|
39 | 24 | return new RuleDefinition(
|
@@ -86,61 +71,9 @@ public function getNodeTypes(): array
|
86 | 71 | */
|
87 | 72 | public function refactor(Node $node): ?Node
|
88 | 73 | {
|
89 |
| - if ($this->testsNodeAnalyzer->isInTestClass($node)) { |
90 |
| - return null; |
91 |
| - } |
92 |
| - |
93 |
| - $class = $node; |
94 |
| - $propertyMetadatas = []; |
95 |
| - |
96 |
| - $this->traverseNodesWithCallable($class, function (Node $node) use ($class, &$propertyMetadatas): ?Node { |
97 |
| - if (! $node instanceof MethodCall) { |
98 |
| - return null; |
99 |
| - } |
100 |
| - |
101 |
| - if (! $this->isName($node->name, 'get')) { |
102 |
| - return null; |
103 |
| - } |
104 |
| - |
105 |
| - if (! $this->isObjectType( |
106 |
| - $node->var, |
107 |
| - new ObjectType('Symfony\Component\DependencyInjection\ContainerInterface') |
108 |
| - )) { |
109 |
| - return null; |
110 |
| - } |
111 |
| - |
112 |
| - if ($node->isFirstClassCallable()) { |
113 |
| - return null; |
114 |
| - } |
115 |
| - |
116 |
| - $args = $node->getArgs(); |
117 |
| - if (count($args) === 1 && $args[0]->value instanceof ClassConstFetch) { |
118 |
| - return null; |
119 |
| - } |
120 |
| - |
121 |
| - $propertyMetadata = $this->dependencyInjectionMethodCallAnalyzer->replaceMethodCallWithPropertyFetchAndDependency( |
122 |
| - $class, |
123 |
| - $node |
124 |
| - ); |
125 |
| - |
126 |
| - if (! $propertyMetadata instanceof PropertyMetadata) { |
127 |
| - return null; |
128 |
| - } |
129 |
| - |
130 |
| - $propertyMetadatas[] = $propertyMetadata; |
131 |
| - return $this->nodeFactory->createPropertyFetch('this', $propertyMetadata->getName()); |
132 |
| - }); |
133 |
| - |
134 |
| - if ($propertyMetadatas === []) { |
135 |
| - return null; |
136 |
| - } |
137 |
| - |
138 |
| - foreach ($propertyMetadatas as $propertyMetadata) { |
139 |
| - $this->classDependencyManipulator->addConstructorDependency($class, $propertyMetadata); |
140 |
| - } |
141 |
| - |
142 |
| - $this->commandConstructorDecorator->decorate($class); |
143 |
| - |
144 |
| - return $node; |
| 74 | + throw new ShouldNotHappenException(sprintf( |
| 75 | + 'The %s rule is deprecated. Use more reliable set \Rector\Symfony\Set\SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION instead', |
| 76 | + self::class |
| 77 | + )); |
145 | 78 | }
|
146 | 79 | }
|
0 commit comments