Skip to content

Commit 41b5e4c

Browse files
authored
[depre] Hard deprecated ContainerGetToConstructorInjectionRector (#725)
1 parent d623cf2 commit 41b5e4c

File tree

1 file changed

+5
-72
lines changed

1 file changed

+5
-72
lines changed

rules/Symfony42/Rector/MethodCall/ContainerGetToConstructorInjectionRector.php

Lines changed: 5 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@
55
namespace Rector\Symfony\Symfony42\Rector\MethodCall;
66

77
use PhpParser\Node;
8-
use PhpParser\Node\Expr\ClassConstFetch;
9-
use PhpParser\Node\Expr\MethodCall;
108
use PhpParser\Node\Stmt\Class_;
11-
use PHPStan\Type\ObjectType;
129
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;
1611
use Rector\Rector\AbstractRector;
17-
use Rector\Symfony\DependencyInjection\NodeDecorator\CommandConstructorDecorator;
18-
use Rector\Symfony\NodeAnalyzer\DependencyInjectionMethodCallAnalyzer;
1912
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2013
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2114

@@ -26,14 +19,6 @@
2619
*/
2720
final class ContainerGetToConstructorInjectionRector extends AbstractRector implements DeprecatedInterface
2821
{
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-
3722
public function getRuleDefinition(): RuleDefinition
3823
{
3924
return new RuleDefinition(
@@ -86,61 +71,9 @@ public function getNodeTypes(): array
8671
*/
8772
public function refactor(Node $node): ?Node
8873
{
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+
));
14578
}
14679
}

0 commit comments

Comments
 (0)