diff --git a/src/Extensions/DoctrineStatementExecuteDynamicReturnTypeExtension.php b/src/Extensions/DoctrineStatementExecuteDynamicReturnTypeExtension.php index 63a661cab..cbad59598 100644 --- a/src/Extensions/DoctrineStatementExecuteDynamicReturnTypeExtension.php +++ b/src/Extensions/DoctrineStatementExecuteDynamicReturnTypeExtension.php @@ -63,7 +63,7 @@ private function inferType(MethodReflection $methodReflection, MethodCall $metho $parameterTypes = $scope->getType($paramsExpr); $stmtReflection = new PdoStatementReflection(); - $queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodReflection, $methodCall); + $queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodCall); if (null === $queryExpr) { return null; } diff --git a/src/Extensions/PdoStatementExecuteTypeSpecifyingExtension.php b/src/Extensions/PdoStatementExecuteTypeSpecifyingExtension.php index 65ec511c8..ca6541f9d 100644 --- a/src/Extensions/PdoStatementExecuteTypeSpecifyingExtension.php +++ b/src/Extensions/PdoStatementExecuteTypeSpecifyingExtension.php @@ -60,7 +60,7 @@ private function inferStatementType(MethodReflection $methodReflection, MethodCa } $stmtReflection = new PdoStatementReflection(); - $queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodReflection, $methodCall); + $queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodCall); if (null === $queryExpr) { return null; } diff --git a/src/PdoReflection/PdoStatementReflection.php b/src/PdoReflection/PdoStatementReflection.php index 2ac7003ea..580156947 100644 --- a/src/PdoReflection/PdoStatementReflection.php +++ b/src/PdoReflection/PdoStatementReflection.php @@ -7,7 +7,6 @@ use PDO; use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; -use PHPStan\Reflection\MethodReflection; use PHPStan\Type\Constant\ConstantArrayType; use PHPStan\Type\Constant\ConstantArrayTypeBuilder; use PHPStan\Type\Constant\ConstantIntegerType; @@ -18,7 +17,7 @@ final class PdoStatementReflection { - public function findPrepareQueryStringExpression(MethodReflection $methodReflection, MethodCall $methodCall): ?Expr + public function findPrepareQueryStringExpression(MethodCall $methodCall): ?Expr { $exprFinder = new ExpressionFinder(); $queryExpr = $exprFinder->findQueryStringExpression($methodCall); @@ -35,10 +34,8 @@ public function findPrepareQueryStringExpression(MethodReflection $methodReflect /** * @param PDO::FETCH* $fetchType - * - * @return Type|null */ - public function getStatementResultType(Type $statementType, int $fetchType) + public function getStatementResultType(Type $statementType, int $fetchType): ?Type { if (!$statementType instanceof GenericObjectType) { return null; @@ -50,7 +47,8 @@ public function getStatementResultType(Type $statementType, int $fetchType) } $resultType = $genericTypes[0]; - if ((PDO::FETCH_NUM === $fetchType || PDO::FETCH_ASSOC === $fetchType) && $resultType instanceof ConstantArrayType) { + if ((PDO::FETCH_NUM === $fetchType || PDO::FETCH_ASSOC === $fetchType) && + $resultType instanceof ConstantArrayType && \count($resultType->getValueTypes()) > 0) { $builder = ConstantArrayTypeBuilder::createEmpty(); $keyTypes = $resultType->getKeyTypes(); diff --git a/src/Rules/PdoStatementExecuteMethodRule.php b/src/Rules/PdoStatementExecuteMethodRule.php index 35981208c..f61e4da84 100644 --- a/src/Rules/PdoStatementExecuteMethodRule.php +++ b/src/Rules/PdoStatementExecuteMethodRule.php @@ -59,7 +59,7 @@ private function checkErrors(MethodReflection $methodReflection, MethodCall $met { $queryReflection = new QueryReflection(); $stmtReflection = new PdoStatementReflection(); - $queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodReflection, $methodCall); + $queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodCall); if (null === $queryExpr) { return [];