Skip to content

Commit 2e86ed1

Browse files
craigfrancisstaabm
andauthored
Do not run PDO namedPlaceholders checks with question mark parameters (#105)
Co-authored-by: Markus Staab <[email protected]>
1 parent ed7aeae commit 2e86ed1

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Rules/PdoStatementExecuteMethodRule.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,17 @@ private function checkParameterValues(MethodCall $methodCall, Scope $scope, stri
124124

125125
$errors = [];
126126
$namedPlaceholders = $this->extractNamedPlaceholders($queryString);
127-
foreach ($namedPlaceholders as $namedPlaceholder) {
128-
if (!\array_key_exists($namedPlaceholder, $parameters)) {
129-
$errors[] = RuleErrorBuilder::message(sprintf('Query expects placeholder %s, but it is missing from values given to execute().', $namedPlaceholder))->line($methodCall->getLine())->build();
127+
if (\count($namedPlaceholders) > 0) {
128+
foreach ($namedPlaceholders as $namedPlaceholder) {
129+
if (!\array_key_exists($namedPlaceholder, $parameters)) {
130+
$errors[] = RuleErrorBuilder::message(sprintf('Query expects placeholder %s, but it is missing from values given to execute().', $namedPlaceholder))->line($methodCall->getLine())->build();
131+
}
130132
}
131-
}
132133

133-
foreach ($parameters as $placeholderKey => $value) {
134-
if (!\in_array($placeholderKey, $namedPlaceholders)) {
135-
$errors[] = RuleErrorBuilder::message(sprintf('Value %s is given to execute(), but the query does not contain this placeholder.', $placeholderKey))->line($methodCall->getLine())->build();
134+
foreach ($parameters as $placeholderKey => $value) {
135+
if (!\in_array($placeholderKey, $namedPlaceholders)) {
136+
$errors[] = RuleErrorBuilder::message(sprintf('Value %s is given to execute(), but the query does not contain this placeholder.', $placeholderKey))->line($methodCall->getLine())->build();
137+
}
136138
}
137139
}
138140

0 commit comments

Comments
 (0)