|
10 | 10 | use PHPStan\Reflection\FunctionReflection;
|
11 | 11 | use PHPStan\Type\Accessory\NonEmptyArrayType;
|
12 | 12 | use PHPStan\Type\ArrayType;
|
13 |
| -use PHPStan\Type\Constant\ConstantArrayType; |
14 | 13 | use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
|
15 | 14 | use PHPStan\Type\Constant\ConstantBooleanType;
|
16 | 15 | use PHPStan\Type\ConstantScalarType;
|
@@ -50,29 +49,46 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
|
50 | 49 | $keysParamType = $scope->getType($firstArg);
|
51 | 50 | $valuesParamType = $scope->getType($secondArg);
|
52 | 51 |
|
53 |
| - if ( |
54 |
| - $keysParamType instanceof ConstantArrayType |
55 |
| - && $valuesParamType instanceof ConstantArrayType |
56 |
| - ) { |
57 |
| - $keyTypes = $keysParamType->getValueTypes(); |
58 |
| - $valueTypes = $valuesParamType->getValueTypes(); |
59 |
| - |
60 |
| - if (count($keyTypes) !== count($valueTypes)) { |
| 52 | + $constantKeysArrays = $keysParamType->getConstantArrays(); |
| 53 | + $constantValuesArrays = $valuesParamType->getConstantArrays(); |
| 54 | + if ($constantKeysArrays !== [] && $constantValuesArrays !== []) { |
| 55 | + if (count($constantKeysArrays) !== count($constantValuesArrays)) { |
61 | 56 | if ($this->phpVersion->throwsTypeErrorForInternalFunctions()) {
|
62 | 57 | return new NeverType();
|
63 | 58 | }
|
64 | 59 | return new ConstantBooleanType(false);
|
65 | 60 | }
|
66 | 61 |
|
67 |
| - $keyTypes = $this->sanitizeConstantArrayKeyTypes($keyTypes); |
68 |
| - if ($keyTypes !== null) { |
| 62 | + $results = []; |
| 63 | + foreach ($constantKeysArrays as $k => $constantKeysArray) { |
| 64 | + $constantValueArrays = $constantValuesArrays[$k]; |
| 65 | + |
| 66 | + $keyTypes = $constantKeysArray->getValueTypes(); |
| 67 | + $valueTypes = $constantValueArrays->getValueTypes(); |
| 68 | + |
| 69 | + if (count($keyTypes) !== count($valueTypes)) { |
| 70 | + if ($this->phpVersion->throwsTypeErrorForInternalFunctions()) { |
| 71 | + return new NeverType(); |
| 72 | + } |
| 73 | + return new ConstantBooleanType(false); |
| 74 | + } |
| 75 | + |
| 76 | + $keyTypes = $this->sanitizeConstantArrayKeyTypes($keyTypes); |
| 77 | + if ($keyTypes === null) { |
| 78 | + continue; |
| 79 | + } |
| 80 | + |
69 | 81 | $builder = ConstantArrayTypeBuilder::createEmpty();
|
70 | 82 | foreach ($keyTypes as $i => $keyType) {
|
71 | 83 | $valueType = $valueTypes[$i];
|
72 | 84 | $builder->setOffsetValueType($keyType, $valueType);
|
73 | 85 | }
|
74 | 86 |
|
75 |
| - return $builder->getArray(); |
| 87 | + $results[] = $builder->getArray(); |
| 88 | + } |
| 89 | + |
| 90 | + if ($results !== []) { |
| 91 | + return TypeCombinator::union(...$results); |
76 | 92 | }
|
77 | 93 | }
|
78 | 94 |
|
|
0 commit comments