Skip to content

Commit 91283ee

Browse files
authored
simplify PdoStatementReflection (#263)
1 parent 10a2be5 commit 91283ee

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

src/Extensions/DoctrineStatementExecuteDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private function inferType(MethodReflection $methodReflection, MethodCall $metho
6363
$parameterTypes = $scope->getType($paramsExpr);
6464

6565
$stmtReflection = new PdoStatementReflection();
66-
$queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodReflection, $methodCall);
66+
$queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodCall);
6767
if (null === $queryExpr) {
6868
return null;
6969
}

src/Extensions/PdoStatementExecuteTypeSpecifyingExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private function inferStatementType(MethodReflection $methodReflection, MethodCa
6060
}
6161

6262
$stmtReflection = new PdoStatementReflection();
63-
$queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodReflection, $methodCall);
63+
$queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodCall);
6464
if (null === $queryExpr) {
6565
return null;
6666
}

src/PdoReflection/PdoStatementReflection.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use PDO;
88
use PhpParser\Node\Expr;
99
use PhpParser\Node\Expr\MethodCall;
10-
use PHPStan\Reflection\MethodReflection;
1110
use PHPStan\Type\Constant\ConstantArrayType;
1211
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
1312
use PHPStan\Type\Constant\ConstantIntegerType;
@@ -18,7 +17,7 @@
1817

1918
final class PdoStatementReflection
2019
{
21-
public function findPrepareQueryStringExpression(MethodReflection $methodReflection, MethodCall $methodCall): ?Expr
20+
public function findPrepareQueryStringExpression(MethodCall $methodCall): ?Expr
2221
{
2322
$exprFinder = new ExpressionFinder();
2423
$queryExpr = $exprFinder->findQueryStringExpression($methodCall);
@@ -35,10 +34,8 @@ public function findPrepareQueryStringExpression(MethodReflection $methodReflect
3534

3635
/**
3736
* @param PDO::FETCH* $fetchType
38-
*
39-
* @return Type|null
4037
*/
41-
public function getStatementResultType(Type $statementType, int $fetchType)
38+
public function getStatementResultType(Type $statementType, int $fetchType): ?Type
4239
{
4340
if (!$statementType instanceof GenericObjectType) {
4441
return null;
@@ -50,7 +47,8 @@ public function getStatementResultType(Type $statementType, int $fetchType)
5047
}
5148

5249
$resultType = $genericTypes[0];
53-
if ((PDO::FETCH_NUM === $fetchType || PDO::FETCH_ASSOC === $fetchType) && $resultType instanceof ConstantArrayType) {
50+
if ((PDO::FETCH_NUM === $fetchType || PDO::FETCH_ASSOC === $fetchType) &&
51+
$resultType instanceof ConstantArrayType && \count($resultType->getValueTypes()) > 0) {
5452
$builder = ConstantArrayTypeBuilder::createEmpty();
5553

5654
$keyTypes = $resultType->getKeyTypes();

src/Rules/PdoStatementExecuteMethodRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function checkErrors(MethodReflection $methodReflection, MethodCall $met
5959
{
6060
$queryReflection = new QueryReflection();
6161
$stmtReflection = new PdoStatementReflection();
62-
$queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodReflection, $methodCall);
62+
$queryExpr = $stmtReflection->findPrepareQueryStringExpression($methodCall);
6363

6464
if (null === $queryExpr) {
6565
return [];

0 commit comments

Comments
 (0)