Skip to content

Commit 79259fa

Browse files
phpstan-botclaude
andcommitted
Use getClassStringObjectType()->getObjectClassReflections() instead of manual ReflectionProvider resolution
The getConstantStrings() loop with ReflectionProvider was redundant: ConstantStringType::getClassStringObjectType() already returns ObjectType(className), whose getObjectClassReflections() provides the same ClassReflection. This removes the ReflectionProvider dependency. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bda843f commit 79259fa

1 file changed

Lines changed: 0 additions & 16 deletions

File tree

src/Type/Php/MethodExistsTypeSpecifyingExtension.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use PHPStan\Analyser\TypeSpecifierContext;
1212
use PHPStan\DependencyInjection\AutowiredService;
1313
use PHPStan\Reflection\FunctionReflection;
14-
use PHPStan\Reflection\ReflectionProvider;
1514
use PHPStan\Type\Accessory\HasMethodType;
1615
use PHPStan\Type\ClassStringType;
1716
use PHPStan\Type\Constant\ConstantBooleanType;
@@ -28,10 +27,6 @@ final class MethodExistsTypeSpecifyingExtension implements FunctionTypeSpecifyin
2827

2928
private TypeSpecifier $typeSpecifier;
3029

31-
public function __construct(private ReflectionProvider $reflectionProvider)
32-
{
33-
}
34-
3530
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
3631
{
3732
$this->typeSpecifier = $typeSpecifier;
@@ -64,17 +59,6 @@ public function specifyTypes(
6459
$objectType = $scope->getType($args[0]->value);
6560
if ($objectType->isString()->yes()) {
6661
if ($objectType->isClassString()->yes()) {
67-
foreach ($objectType->getConstantStrings() as $constantString) {
68-
if (!$this->reflectionProvider->hasClass($constantString->getValue())) {
69-
continue;
70-
}
71-
72-
$classReflection = $this->reflectionProvider->getClass($constantString->getValue());
73-
if ($classReflection->hasMethod($methodNameType->getValue()) && !$classReflection->hasNativeMethod($methodNameType->getValue())) {
74-
return $this->createFuncCallSpec($node, $context, $scope);
75-
}
76-
}
77-
7862
foreach ($objectType->getClassStringObjectType()->getObjectClassReflections() as $classReflection) {
7963
if ($classReflection->hasMethod($methodNameType->getValue()) && !$classReflection->hasNativeMethod($methodNameType->getValue())) {
8064
return $this->createFuncCallSpec($node, $context, $scope);

0 commit comments

Comments
 (0)