13
13
use PHPStan \Type \Constant \ConstantArrayType ;
14
14
use PHPStan \Type \Constant \ConstantArrayTypeBuilder ;
15
15
use PHPStan \Type \Constant \ConstantBooleanType ;
16
- use PHPStan \Type \Constant \ConstantIntegerType ;
17
- use PHPStan \Type \Constant \ConstantStringType ;
16
+ use PHPStan \Type \ConstantScalarType ;
18
17
use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
19
18
use PHPStan \Type \ErrorType ;
20
19
use PHPStan \Type \MixedType ;
23
22
use PHPStan \Type \TypeCombinator ;
24
23
use PHPStan \Type \UnionType ;
25
24
use function count ;
25
+ use function is_int ;
26
+ use function is_string ;
26
27
27
28
#[AutowiredService]
28
29
final class ArrayCombineFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
@@ -114,7 +115,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
114
115
/**
115
116
* @param array<int, Type> $types
116
117
*
117
- * @return array<int, ConstantIntegerType|ConstantStringType >|null
118
+ * @return list<ConstantScalarType >|null
118
119
*/
119
120
private function sanitizeConstantArrayKeyTypes (array $ types ): ?array
120
121
{
@@ -125,14 +126,19 @@ private function sanitizeConstantArrayKeyTypes(array $types): ?array
125
126
$ type = $ type ->toString ();
126
127
}
127
128
128
- if (
129
- !$ type instanceof ConstantIntegerType
130
- && !$ type instanceof ConstantStringType
131
- ) {
129
+ $ scalars = $ type ->getConstantScalarTypes ();
130
+ if (count ($ scalars ) === 0 ) {
132
131
return null ;
133
132
}
134
133
135
- $ sanitizedTypes [] = $ type ;
134
+ foreach ($ scalars as $ scalar ) {
135
+ $ value = $ scalar ->getValue ();
136
+ if (!is_int ($ value ) && !is_string ($ value )) {
137
+ return null ;
138
+ }
139
+
140
+ $ sanitizedTypes [] = $ scalar ;
141
+ }
136
142
}
137
143
138
144
return $ sanitizedTypes ;
0 commit comments