diff --git a/src/QueryReflection/PlaceholderValidation.php b/src/QueryReflection/PlaceholderValidation.php index 8200b933d..c8419de65 100644 --- a/src/QueryReflection/PlaceholderValidation.php +++ b/src/QueryReflection/PlaceholderValidation.php @@ -46,6 +46,10 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it } } + if ($minPlaceholderCount === PHP_INT_MAX) { + $minPlaceholderCount = 0; + } + yield from $this->validateUnnamedPlaceholders($parameters, $minPlaceholderCount, $maxPlaceholderCount); } diff --git a/tests/rules/PdoStatementExecuteMethodRuleTest.php b/tests/rules/PdoStatementExecuteMethodRuleTest.php index dd93ad3da..9117894b3 100644 --- a/tests/rules/PdoStatementExecuteMethodRuleTest.php +++ b/tests/rules/PdoStatementExecuteMethodRuleTest.php @@ -125,6 +125,10 @@ public function testPlaceholderBug(): void 'Query expects 2-3 placeholders, but 1-3 values are given.', 42, ], + [ + 'Query expects 2 placeholders, but no values are given.', + 48, + ], ]); } } diff --git a/tests/rules/data/placeholder-bug.php b/tests/rules/data/placeholder-bug.php index dae9861bb..4957f68ff 100644 --- a/tests/rules/data/placeholder-bug.php +++ b/tests/rules/data/placeholder-bug.php @@ -41,4 +41,10 @@ public function sometimesWrongNumberOfParameters(PDO $pdo, $vkFrom) $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ' . $fromCondition); $stmt->execute($values); } + + public function wrongMinBound(PDO $pdo) + { + $stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? '); + $stmt->execute([]); + } }