Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 4 additions & 6 deletions src/PdoReflection/PdoStatementReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/PdoStatementExecuteMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down