|
6 | 6 | use PhpParser\Node\Expr\New_; |
7 | 7 | use PHPStan\Analyser\Scope; |
8 | 8 | use PHPStan\Internal\SprintfHelper; |
| 9 | +use PHPStan\Reflection\ClassReflection; |
9 | 10 | use PHPStan\Reflection\ParametersAcceptorSelector; |
10 | 11 | use PHPStan\Reflection\Php\PhpMethodReflection; |
11 | 12 | use PHPStan\Reflection\ReflectionProvider; |
|
17 | 18 | use PHPStan\Rules\RuleErrorBuilder; |
18 | 19 | use PHPStan\ShouldNotHappenException; |
19 | 20 | use PHPStan\Type\Constant\ConstantStringType; |
20 | | -use PHPStan\Type\VerbosityLevel; |
21 | 21 | use function array_filter; |
22 | 22 | use function array_map; |
23 | 23 | use function array_merge; |
24 | 24 | use function count; |
25 | 25 | use function sprintf; |
26 | | -use function str_starts_with; |
27 | 26 | use function strtolower; |
28 | 27 |
|
29 | 28 | /** |
@@ -248,16 +247,18 @@ private function getClassNames(Node $node, Scope $scope): array |
248 | 247 |
|
249 | 248 | $type = $scope->getType($node->class); |
250 | 249 |
|
251 | | - if (str_starts_with($type->describe(VerbosityLevel::precise()), 'class-string')) { |
252 | | - $classStringObjectType = $type->getClassStringObjectType(); |
253 | | - |
254 | | - return array_map( |
255 | | - static fn (string $name): array => [$name, true], |
256 | | - array_filter($classStringObjectType->getObjectClassNames(), function (string $name): bool { |
257 | | - $reflectionClass = $this->reflectionProvider->getClass($name); |
258 | | - return !$reflectionClass->isAbstract() && !$reflectionClass->isInterface(); |
259 | | - }), |
| 250 | + if ($type->isClassString()->yes()) { |
| 251 | + $concretes = array_filter( |
| 252 | + $type->getClassStringObjectType()->getObjectClassReflections(), |
| 253 | + static fn (ClassReflection $classReflection): bool => !$classReflection->isAbstract() && !$classReflection->isInterface(), |
260 | 254 | ); |
| 255 | + |
| 256 | + if (0 < count($concretes)) { |
| 257 | + return array_map( |
| 258 | + static fn (ClassReflection $classReflection): array => [$classReflection->getName(), true], |
| 259 | + $concretes, |
| 260 | + ); |
| 261 | + } |
261 | 262 | } |
262 | 263 |
|
263 | 264 | return array_merge( |
|
0 commit comments