|
13 | 13 | use PHPStan\Reflection\ReflectionProvider\ReflectionProviderProvider; |
14 | 14 | use PHPStan\ShouldNotHappenException; |
15 | 15 | use PHPStan\Type\Accessory\AccessoryNonFalsyStringType; |
| 16 | +use PHPStan\Type\ArrayType; |
| 17 | +use PHPStan\Type\Constant\ConstantArrayType; |
16 | 18 | use PHPStan\Type\Constant\ConstantFloatType; |
17 | 19 | use PHPStan\Type\Constant\ConstantIntegerType; |
18 | 20 | use PHPStan\Type\Constant\ConstantStringType; |
@@ -424,7 +426,7 @@ public function resolveConstantType(string $constantName, Type $constantType): T |
424 | 426 | return $constantType; |
425 | 427 | } |
426 | 428 | if (in_array($constantName, $this->dynamicConstantNames, true)) { |
427 | | - return $constantType->generalize(GeneralizePrecision::lessSpecific()); |
| 429 | + return $this->generalizeDynamicConstantType($constantType); |
428 | 430 | } |
429 | 431 | } |
430 | 432 |
|
@@ -459,13 +461,23 @@ public function resolveClassConstantType(string $className, string $constantName |
459 | 461 | } |
460 | 462 |
|
461 | 463 | if ($constantType->isConstantValue()->yes()) { |
462 | | - return $constantType->generalize(GeneralizePrecision::lessSpecific()); |
| 464 | + return $this->generalizeDynamicConstantType($constantType); |
463 | 465 | } |
464 | 466 | } |
465 | 467 |
|
466 | 468 | return $constantType; |
467 | 469 | } |
468 | 470 |
|
| 471 | + private function generalizeDynamicConstantType(Type $constantType): Type |
| 472 | + { |
| 473 | + $generalized = $constantType->generalize(GeneralizePrecision::lessSpecific()); |
| 474 | + if ($generalized->equals(new ConstantArrayType([], []))) { |
| 475 | + return new ArrayType(new MixedType(), new MixedType()); |
| 476 | + } |
| 477 | + |
| 478 | + return $generalized; |
| 479 | + } |
| 480 | + |
469 | 481 | private function createInteger(?int $min, ?int $max): Type |
470 | 482 | { |
471 | 483 | if ($min !== null && $min === $max) { |
|
0 commit comments