@@ -32,7 +32,8 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
32
32
33
33
public function getTypeFromFunctionCall (FunctionReflection $ functionReflection , FuncCall $ functionCall , Scope $ scope ): ?Type
34
34
{
35
- if (count ($ functionCall ->getArgs ()) < 2 ) {
35
+ $ numArgs = count ($ functionCall ->getArgs ());
36
+ if ($ numArgs < 2 ) {
36
37
return null ;
37
38
}
38
39
@@ -54,10 +55,41 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
54
55
)->getReturnType ();
55
56
} elseif ($ callableIsNull ) {
56
57
$ arrayBuilder = ConstantArrayTypeBuilder::createEmpty ();
58
+ $ argIterableValueTypes = [];
59
+ $ addNull = false ;
60
+ $ expectedSize = null ;
57
61
foreach (array_slice ($ functionCall ->getArgs (), 1 ) as $ index => $ arg ) {
62
+ $ argType = $ scope ->getType ($ arg ->value );
63
+ $ argIterableValueTypes [$ index ] = $ argType ->getIterableValueType ();
64
+ if ($ addNull ) {
65
+ continue ;
66
+ }
67
+
68
+ $ arraySizes = $ argType ->getArraySize ()->getConstantScalarValues ();
69
+ if ($ arraySizes === []) {
70
+ $ addNull = true ;
71
+ continue ;
72
+ }
73
+
74
+ foreach ($ arraySizes as $ size ) {
75
+ $ expectedSize ??= $ size ;
76
+ if ($ expectedSize === $ size ) {
77
+ continue ;
78
+ }
79
+
80
+ $ addNull = true ;
81
+ break ;
82
+ }
83
+ }
84
+
85
+ foreach ($ argIterableValueTypes as $ index => $ offsetValueType ) {
86
+ if ($ addNull ) {
87
+ $ offsetValueType = TypeCombinator::addNull ($ offsetValueType );
88
+ }
89
+
58
90
$ arrayBuilder ->setOffsetValueType (
59
91
new ConstantIntegerType ($ index ),
60
- $ scope -> getType ( $ arg -> value )-> getIterableValueType () ,
92
+ $ offsetValueType ,
61
93
);
62
94
}
63
95
$ valueType = $ arrayBuilder ->getArray ();
0 commit comments