88use Composer \Semver \VersionParser ;
99use Doctrine \DBAL \Connection ;
1010use Doctrine \DBAL \Result ;
11- use Doctrine \DBAL \Statement ;
1211use PhpParser \Node \Expr ;
1312use PhpParser \Node \Expr \MethodCall ;
1413use PHPStan \Analyser \Scope ;
2120use staabm \PHPStanDba \QueryReflection \QueryReflection ;
2221use staabm \PHPStanDba \QueryReflection \QueryReflector ;
2322
24- final class DoctrineConnectionDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
23+ final class DoctrineConnectionQueryDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
2524{
26- /**
27- * @var array<string, class-string> return types of Connection methods in doctrine 3.x
28- */
29- private $ resultMap = [
30- 'query ' => Result::class,
31- //'prepare' => Statement::class,
32- ];
33-
3425 public function getClass (): string
3526 {
3627 return Connection::class;
3728 }
3829
3930 public function isMethodSupported (MethodReflection $ methodReflection ): bool
4031 {
41- return \in_array (strtolower ($ methodReflection ->getName ()), ['query ' /*, 'prepare'*/ ], true );
32+ return \in_array (strtolower ($ methodReflection ->getName ()), ['query ' ], true );
4233 }
4334
4435 public function getTypeFromMethodCall (MethodReflection $ methodReflection , MethodCall $ methodCall , Scope $ scope ): Type
@@ -63,26 +54,25 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
6354 return $ defaultReturn ;
6455 }
6556
66- $ resultType = $ this ->inferType ($ methodReflection , $ args [0 ]->value , $ scope );
57+ $ resultType = $ this ->inferType ($ args [0 ]->value , $ scope );
6758 if (null !== $ resultType ) {
6859 return $ resultType ;
6960 }
7061
7162 return $ defaultReturn ;
7263 }
7364
74- private function inferType (MethodReflection $ methodReflection , Expr $ queryExpr , Scope $ scope ): ?Type
65+ private function inferType (Expr $ queryExpr , Scope $ scope ): ?Type
7566 {
7667 $ queryReflection = new QueryReflection ();
7768 $ queryString = $ queryReflection ->resolveQueryString ($ queryExpr , $ scope );
7869 if (null === $ queryString ) {
7970 return null ;
8071 }
8172
82- $ genericMainType = $ this ->resultMap [strtolower ($ methodReflection ->getName ())];
8373 $ resultType = $ queryReflection ->getResultType ($ queryString , QueryReflector::FETCH_TYPE_BOTH );
8474 if ($ resultType ) {
85- return new GenericObjectType ($ genericMainType , [$ resultType ]);
75+ return new GenericObjectType (Result::class , [$ resultType ]);
8676 }
8777
8878 return null ;
0 commit comments