@@ -48,6 +48,7 @@ public function getClass(): string
4848 public function isMethodSupported (MethodReflection $ methodReflection ): bool
4949 {
5050 return in_array ($ methodReflection ->getName (), [
51+ 'getResult ' ,
5152 'getResultArray ' ,
5253 'getResultObject ' ,
5354 'getRowArray ' ,
@@ -59,6 +60,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
5960 public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): ?Type
6061 {
6162 return match ($ methodReflection ->getName ()) {
63+ 'getResult ' => $ this ->resultType ($ methodCall , $ scope ),
6264 'getResultArray ' => $ this ->listOf (new ArrayType (new StringType (), new MixedType ())),
6365 'getResultObject ' => $ this ->listOf (new ObjectType (stdClass::class)),
6466 'getRowArray ' => TypeCombinator::addNull (new ArrayType (new StringType (), new MixedType ())),
@@ -68,6 +70,33 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
6870 };
6971 }
7072
73+ /**
74+ * Types `getResult($type)` from its constant `$type`: `'array'`, `'object'` (the default), or a
75+ * class name. A non-constant `$type` leaves the framework's declared `array`.
76+ */
77+ private function resultType (MethodCall $ methodCall , Scope $ scope ): ?Type
78+ {
79+ $ args = $ methodCall ->getArgs ();
80+
81+ if (! isset ($ args [0 ])) {
82+ return $ this ->listOf (new ObjectType (stdClass::class));
83+ }
84+
85+ $ strings = $ scope ->getType ($ args [0 ]->value )->getConstantStrings ();
86+
87+ if (count ($ strings ) !== 1 ) {
88+ return null ;
89+ }
90+
91+ $ value = $ strings [0 ]->getValue ();
92+
93+ return match ($ value ) {
94+ 'array ' => $ this ->listOf (new ArrayType (new StringType (), new MixedType ())),
95+ 'object ' => $ this ->listOf (new ObjectType (stdClass::class)),
96+ default => $ this ->listOf ($ this ->reflectionProvider ->hasClass ($ value ) ? new ObjectType ($ value ) : new ObjectWithoutClassType ()),
97+ };
98+ }
99+
71100 private function customObjectType (MethodCall $ methodCall , Scope $ scope ): Type
72101 {
73102 $ args = $ methodCall ->getArgs ();
0 commit comments