1515use PHPStan \Type \Constant \ConstantBooleanType ;
1616use PHPStan \Type \Constant \ConstantIntegerType ;
1717use PHPStan \Type \Constant \ConstantStringType ;
18+ use PHPStan \Type \ConstantScalarType ;
1819use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
1920use PHPStan \Type \ErrorType ;
2021use PHPStan \Type \MixedType ;
2324use PHPStan \Type \TypeCombinator ;
2425use PHPStan \Type \UnionType ;
2526use function count ;
27+ use function is_int ;
28+ use function is_string ;
2629
2730#[AutowiredService]
2831final class ArrayCombineFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
@@ -114,7 +117,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
114117 /**
115118 * @param array<int, Type> $types
116119 *
117- * @return array<int, ConstantIntegerType|ConstantStringType >|null
120+ * @return list<ConstantScalarType >|null
118121 */
119122 private function sanitizeConstantArrayKeyTypes (array $ types ): ?array
120123 {
@@ -125,14 +128,19 @@ private function sanitizeConstantArrayKeyTypes(array $types): ?array
125128 $ type = $ type ->toString ();
126129 }
127130
128- if (
129- !$ type instanceof ConstantIntegerType
130- && !$ type instanceof ConstantStringType
131- ) {
131+ $ scalars = $ type ->getConstantScalarTypes ();
132+ if (count ($ scalars ) === 0 ) {
132133 return null ;
133134 }
134135
135- $ sanitizedTypes [] = $ type ;
136+ foreach ($ scalars as $ scalar ) {
137+ $ value = $ scalar ->getValue ();
138+ if (!is_int ($ value ) && !is_string ($ value )) {
139+ return null ;
140+ }
141+
142+ $ sanitizedTypes [] = $ scalar ;
143+ }
136144 }
137145
138146 return $ sanitizedTypes ;
0 commit comments