Skip to content

Commit ff961bc

Browse files
committed
Fix
1 parent 9e154e2 commit ff961bc

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

rules/CodeQuality/Rector/Class_/ControllerMethodInjectionToConstructorRector.php

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ public function refactor(Node $node): ?Node
118118

119119
$propertyMetadatas = [];
120120

121+
$constructParamVariables = [];
122+
$constructClassMethod = $node->getMethod(MethodName::CONSTRUCT);
123+
if ($constructClassMethod instanceof ClassMethod) {
124+
foreach ($constructClassMethod->params as $param) {
125+
if ($param->type instanceof FullyQualified) {
126+
$constructParamVariables[$param->type->toString()] = $this->getName($param->var);
127+
}
128+
}
129+
}
130+
121131
foreach ($node->getMethods() as $classMethod) {
122132
if ($this->shouldSkipClassMethod($classMethod)) {
123133
continue;
@@ -152,10 +162,20 @@ public function refactor(Node $node): ?Node
152162

153163
$paramType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($param->type);
154164

155-
if ($paramType instanceof ObjectType) {
156-
if ($paramType->isEnum()->yes()) {
157-
continue;
158-
}
165+
if (! $paramType instanceof ObjectType) {
166+
continue;
167+
}
168+
169+
if ($paramType->isEnum()->yes()) {
170+
continue;
171+
}
172+
173+
if (
174+
in_array($this->getName($param->var), $constructParamVariables, true)
175+
&&
176+
! in_array($this->getName($param->type), array_keys($constructParamVariables), true)
177+
) {
178+
continue;
159179
}
160180

161181
unset($classMethod->params[$key]);

0 commit comments

Comments
 (0)