66
77use mysqli ;
88use mysqli_result ;
9+ use PhpParser \Node \Expr ;
910use PhpParser \Node \Expr \FuncCall ;
1011use PhpParser \Node \Expr \MethodCall ;
1112use PHPStan \Analyser \Scope ;
@@ -62,22 +63,9 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
6263 return $ defaultReturn ;
6364 }
6465
65- $ queryReflection = new QueryReflection ();
66- $ queryString = $ queryReflection ->resolveQueryString ($ args [1 ]->value , $ scope );
67- if (null === $ queryString ) {
68- return $ defaultReturn ;
69- }
70-
71- $ resultType = $ queryReflection ->getResultType ($ queryString , QueryReflector::FETCH_TYPE_ASSOC );
72- if ($ resultType ) {
73- if (QueryReflection::getRuntimeConfiguration ()->throwsMysqliExceptions ($ this ->phpVersion )) {
74- return new GenericObjectType (mysqli_result::class, [$ resultType ]);
75- }
76-
77- return TypeCombinator::union (
78- new GenericObjectType (mysqli_result::class, [$ resultType ]),
79- new ConstantBooleanType (false ),
80- );
66+ $ resultType = $ this ->inferResultType ($ args [1 ]->value , $ scope );
67+ if (null !== $ resultType ) {
68+ return $ resultType ;
8169 }
8270
8371 return $ defaultReturn ;
@@ -96,10 +84,20 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
9684 return $ defaultReturn ;
9785 }
9886
87+ $ resultType = $ this ->inferResultType ($ args [0 ]->value , $ scope );
88+ if (null !== $ resultType ) {
89+ return $ resultType ;
90+ }
91+
92+ return $ defaultReturn ;
93+ }
94+
95+ private function inferResultType (Expr $ queryExpr , Scope $ scope ): ?Type
96+ {
9997 $ queryReflection = new QueryReflection ();
100- $ queryString = $ queryReflection ->resolveQueryString ($ args [ 0 ]-> value , $ scope );
98+ $ queryString = $ queryReflection ->resolveQueryString ($ queryExpr , $ scope );
10199 if (null === $ queryString ) {
102- return $ defaultReturn ;
100+ return null ;
103101 }
104102
105103 $ resultType = $ queryReflection ->getResultType ($ queryString , QueryReflector::FETCH_TYPE_ASSOC );
@@ -114,6 +112,6 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
114112 );
115113 }
116114
117- return $ defaultReturn ;
115+ return null ;
118116 }
119117}
0 commit comments