1313use PHPStan \Type \Constant \ConstantArrayType ;
1414use PHPStan \Type \Constant \ConstantArrayTypeBuilder ;
1515use PHPStan \Type \Constant \ConstantBooleanType ;
16- use PHPStan \Type \Constant \ConstantIntegerType ;
17- use PHPStan \Type \Constant \ConstantStringType ;
16+ use PHPStan \Type \ConstantScalarType ;
1817use PHPStan \Type \DynamicFunctionReturnTypeExtension ;
1918use PHPStan \Type \ErrorType ;
2019use PHPStan \Type \MixedType ;
2322use PHPStan \Type \TypeCombinator ;
2423use PHPStan \Type \UnionType ;
2524use function count ;
25+ use function is_int ;
26+ use function is_string ;
2627
2728#[AutowiredService]
2829final class ArrayCombineFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
@@ -114,7 +115,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
114115 /**
115116 * @param array<int, Type> $types
116117 *
117- * @return array<int, ConstantIntegerType|ConstantStringType >|null
118+ * @return list<ConstantScalarType >|null
118119 */
119120 private function sanitizeConstantArrayKeyTypes (array $ types ): ?array
120121 {
@@ -125,14 +126,19 @@ private function sanitizeConstantArrayKeyTypes(array $types): ?array
125126 $ type = $ type ->toString ();
126127 }
127128
128- if (
129- !$ type instanceof ConstantIntegerType
130- && !$ type instanceof ConstantStringType
131- ) {
129+ $ scalars = $ type ->getConstantScalarTypes ();
130+ if (count ($ scalars ) === 0 ) {
132131 return null ;
133132 }
134133
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+ }
136142 }
137143
138144 return $ sanitizedTypes ;
0 commit comments