@@ -39,19 +39,49 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
3939
4040 $ array = $ args [0 ]->value ;
4141 $ callable = $ args [1 ]->value ;
42+
43+
4244 if ($ callable instanceof Expr \ArrowFunction && $ callable ->expr instanceof Expr \FuncCall) {
43- $ specifiedTypesInCallable = $ this ->typeSpecifier ->specifyTypesInCondition ($ scope , $ callable ->expr , $ context )->getSureTypes ();
44- $ callableParm = $ callable ->params [0 ];
45- if (!$ callableParm instanceof Expr \Variable || !key_exists ("$ " . $ callableParm ->name , $ specifiedTypesInCallable )) {
46- return new SpecifiedTypes ();
45+
46+ $ callableParms = $ callable ->params ;
47+ $ specifiedTypesInFuncCall = $ this ->typeSpecifier ->specifyTypesInCondition ($ scope , $ callable ->expr , $ context )->getSureTypes ();
48+
49+ if (count ($ callableParms ) >= 1 && $ callableParms [0 ] instanceof Expr \Variable) {
50+
51+ $ callableParmValueName = $ callableParms [0 ]->name ;
52+ $ specifiedTypeOfValue = array_find (
53+ $ specifiedTypesInFuncCall ,
54+ fn ($ specifiedType ) => $ specifiedType [0 ] instanceof Expr \Variable && $ specifiedType [0 ]->name === $ callableParmValueName
55+ );
56+
57+ if (isset ($ specifiedTypeOfValue )) {
58+ $ valueType = $ specifiedTypeOfValue [1 ];
59+ }
60+
61+ }
62+
63+ if (count ($ callableParms ) >= 2 && $ callableParms [1 ] instanceof Expr \Variable) {
64+
65+ $ callableParmKeyName = $ callableParms [1 ]->name ;
66+ $ specifiedTypeOfKey = array_find (
67+ $ specifiedTypesInFuncCall ,
68+ fn ($ specifiedType ) => $ specifiedType [0 ] instanceof Expr \Variable && $ specifiedType [0 ]->name === $ callableParmKeyName
69+ );
70+
71+ if (isset ($ specifiedTypeOfKey )) {
72+ $ keyType = $ specifiedTypeOfKey [1 ];
73+ }
74+
75+ }
76+
77+ if (isset ($ keyType ) || isset ($ valueType )) {
78+ return $ this ->typeSpecifier ->create (
79+ $ array ,
80+ new ArrayType ($ keyType ?? new MixedType (), $ valueType ?? new MixedType ()),
81+ $ context ,
82+ $ scope
83+ );
4784 }
48- $ ItemType = $ specifiedTypesInCallable ["$ " . $ callableParm ->name ][1 ];
49- return $ this ->typeSpecifier ->create (
50- $ array ,
51- new ArrayType (new MixedType (), $ ItemType ),
52- $ context ,
53- $ scope
54- );
5585 }
5686
5787 return new SpecifiedTypes ();
0 commit comments