Skip to content

Commit

Permalink
Trigger deprecation warning when fixing query params
Browse files Browse the repository at this point in the history
  • Loading branch information
kpicaza committed Feb 15, 2022
1 parent 450d7dd commit a551a8d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Sifo/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,27 @@ private function fixQueryParamsForMultidimensionalArray(string $query, array $pa
return $params;
}

$query = str_replace(["\r", "\n", PHP_EOL], ' ', $query);
$param_count = preg_match_all('`(?:\s|,|\()(\?)(?:;|,|\)|)`', $query);
$split_query = explode('?', $query);
$bind_count = count($split_query) - 1;
$params = is_array($params[0]) ? $params[0] : $params;
$params_count = count($params);

if (count($params) > $param_count) {
array_splice($params, -(count($params) - $param_count));
if ($params_count > $bind_count) {
$template = <<<EOF
Adding more parameters than query binds will be not allowed starting from 3.1.0 version.
Query: %s
Params: %s
Bindings: %s
EOF;

trigger_error(
sprintf($template, $query, var_export($params, true), $bind_count),
\E_USER_DEPRECATED
);

array_splice($params, -(count($params) - $bind_count));
}

return $params;
Expand Down

0 comments on commit a551a8d

Please sign in to comment.