|
19 | 19 | use PHPStan\Analyser\TypeSpecifierContext;
|
20 | 20 | use PHPStan\ShouldNotHappenException;
|
21 | 21 | use PHPStan\Type\ArrayType;
|
22 |
| -use PHPStan\Type\Constant\ConstantArrayType; |
23 | 22 | use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
|
24 |
| -use PHPStan\Type\Constant\ConstantStringType; |
25 | 23 | use PHPStan\Type\IterableType;
|
26 | 24 | use PHPStan\Type\MixedType;
|
27 | 25 | use PHPStan\Type\NeverType;
|
@@ -139,11 +137,12 @@ static function (Type $type): Type {
|
139 | 137 |
|
140 | 138 | if ($assertName === 'notIsInstanceOf') {
|
141 | 139 | $classType = $scope->getType($args[1]->value);
|
142 |
| - if (!$classType instanceof ConstantStringType) { |
| 140 | + $constantStrings = $classType->getConstantStrings(); |
| 141 | + if (count($constantStrings) !== 1) { |
143 | 142 | return new SpecifiedTypes([], []);
|
144 | 143 | }
|
145 | 144 |
|
146 |
| - $objectType = new ObjectType($classType->getValue()); |
| 145 | + $objectType = new ObjectType($constantStrings[0]->getValue()); |
147 | 146 | return self::allArrayOrIterable(
|
148 | 147 | $typeSpecifier,
|
149 | 148 | $scope,
|
@@ -181,14 +180,15 @@ private static function allArrayOrIterable(
|
181 | 180 | if (count($arrayTypes) > 0) {
|
182 | 181 | $newArrayTypes = [];
|
183 | 182 | foreach ($arrayTypes as $arrayType) {
|
184 |
| - if ($arrayType instanceof ConstantArrayType) { |
| 183 | + $constantArrays = $arrayType->getConstantArrays(); |
| 184 | + if (count($constantArrays) === 1) { |
185 | 185 | $builder = ConstantArrayTypeBuilder::createEmpty();
|
186 |
| - foreach ($arrayType->getKeyTypes() as $i => $keyType) { |
187 |
| - $valueType = $typeCallback($arrayType->getValueTypes()[$i]); |
| 186 | + foreach ($constantArrays[0]->getKeyTypes() as $i => $keyType) { |
| 187 | + $valueType = $typeCallback($constantArrays[0]->getValueTypes()[$i]); |
188 | 188 | if ($valueType instanceof NeverType) {
|
189 | 189 | continue 2;
|
190 | 190 | }
|
191 |
| - $builder->setOffsetValueType($keyType, $valueType, $arrayType->isOptionalKey($i)); |
| 191 | + $builder->setOffsetValueType($keyType, $valueType, $constantArrays[0]->isOptionalKey($i)); |
192 | 192 | }
|
193 | 193 | $newArrayTypes[] = $builder->getArray();
|
194 | 194 | } else {
|
@@ -308,25 +308,27 @@ private static function getExpressionResolvers(): array
|
308 | 308 | },
|
309 | 309 | 'isInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr {
|
310 | 310 | $classType = $scope->getType($class->value);
|
311 |
| - if (!$classType instanceof ConstantStringType) { |
| 311 | + $constantStrings = $classType->getConstantStrings(); |
| 312 | + if (count($constantStrings) !== 1) { |
312 | 313 | return null;
|
313 | 314 | }
|
314 | 315 |
|
315 | 316 | return new Instanceof_(
|
316 | 317 | $expr->value,
|
317 |
| - new Name($classType->getValue()) |
| 318 | + new Name($constantStrings[0]->getValue()) |
318 | 319 | );
|
319 | 320 | },
|
320 | 321 | 'notIsInstanceOf' => static function (Scope $scope, Arg $expr, Arg $class): ?Expr {
|
321 | 322 | $classType = $scope->getType($class->value);
|
322 |
| - if (!$classType instanceof ConstantStringType) { |
| 323 | + $constantStrings = $classType->getConstantStrings(); |
| 324 | + if (count($constantStrings) !== 1) { |
323 | 325 | return null;
|
324 | 326 | }
|
325 | 327 |
|
326 | 328 | return new BooleanNot(
|
327 | 329 | new Instanceof_(
|
328 | 330 | $expr->value,
|
329 |
| - new Name($classType->getValue()) |
| 331 | + new Name($constantStrings[0]->getValue()) |
330 | 332 | )
|
331 | 333 | );
|
332 | 334 | },
|
|
0 commit comments