|
15 | 15 | use PhpParser\Node\Expr\Variable; |
16 | 16 | use PhpParser\Node\Name; |
17 | 17 | use PhpParser\Node\Stmt\ClassMethod; |
18 | | -use PHPStan\Reflection\ClassReflection; |
19 | 18 | use Rector\Arguments\Contract\ReplaceArgumentDefaultValueInterface; |
20 | 19 | use Rector\Arguments\ValueObject\ReplaceArgumentDefaultValue; |
21 | 20 | use Rector\NodeAnalyzer\ArgsAnalyzer; |
22 | 21 | use Rector\NodeTypeResolver\NodeTypeResolver; |
23 | 22 | use Rector\PhpParser\AstResolver; |
24 | 23 | use Rector\PhpParser\Node\NodeFactory; |
25 | 24 | use Rector\PhpParser\Node\Value\ValueResolver; |
26 | | -use Rector\PHPStan\ScopeFetcher; |
27 | 25 | use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; |
28 | 26 |
|
29 | 27 | final readonly class ArgumentDefaultValueReplacer |
@@ -159,14 +157,16 @@ private function processArgs( |
159 | 157 | if (is_scalar( |
160 | 158 | $replaceArgumentDefaultValue->getValueBefore() |
161 | 159 | ) && $argValue === $replaceArgumentDefaultValue->getValueBefore()) { |
162 | | - $scope = ScopeFetcher::fetch($particularArg); |
163 | | - if ($scope->getClassReflection() instanceof ClassReflection |
164 | | - && $particularArg->value instanceof ClassConstFetch |
| 160 | + if ($particularArg->value instanceof ClassConstFetch |
165 | 161 | && $particularArg->value->class instanceof Name |
166 | | - && $particularArg->value->class->isSpecialClassName()) { |
167 | | - $classReflection = $scope->getClassReflection(); |
| 162 | + && $particularArg->value->class->isSpecialClassName() |
| 163 | + && is_string($replaceArgumentDefaultValue->getValueAfter()) |
| 164 | + && str_contains($replaceArgumentDefaultValue->getValueAfter(), '::')) { |
| 165 | + [$targetClass, $targetConstant] = explode('::', $replaceArgumentDefaultValue->getValueAfter()); |
168 | 166 | $type = $this->nodeTypeResolver->getType($particularArg->value->class); |
169 | | - if ($type instanceof FullyQualifiedObjectType && $classReflection->getName() === $type->getClassName()) { |
| 167 | + if ($type instanceof FullyQualifiedObjectType |
| 168 | + && $type->getClassName() === $targetClass |
| 169 | + && $particularArg->value->name->toString() === $targetConstant) { |
170 | 170 | return null; |
171 | 171 | } |
172 | 172 | } |
|
0 commit comments