Skip to content

Commit 2df41d3

Browse files
authored
Minor refactoring of Query (#1116)
1 parent 7a998b2 commit 2df41d3

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
- Enh #929: Implement lazy arrays for array, structured and JSON column types (@Tigrov)
7171
- Bug #933: Explicitly mark nullable parameters (@vjik)
7272
- Chg #911, #1113: Change supported PHP versions to `8.1 - 8.5` (@Tigrov, @vjik)
73-
- Enh #911, #940: Minor refactoring (@Tigrov)
73+
- Enh #911, #940, #1116: Minor refactoring (@Tigrov)
7474
- Chg #938, #936, #937: Remove `ext-json`, `ext-ctype`, `ext-mbstring` from `require` section of `composer.json` (@Tigrov)
7575
- Chg #936: Remove `hasLimit()` and `hasOffset()` methods from `AbstractDQLQueryBuilder` class (@Tigrov)
7676
- Chg #937: Remove `baseName()` and `pascalCaseToId()` methods from `DbStringHelper` (@Tigrov)

src/Query/Query.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use function array_key_exists;
2323
use function array_map;
2424
use function array_merge;
25+
use function array_push;
2526
use function array_shift;
2627
use function array_unshift;
2728
use function count;
@@ -152,16 +153,18 @@ public function addParams(array $params): static
152153

153154
if (empty($this->params)) {
154155
$this->params = $params;
155-
} else {
156-
foreach ($params as $name => $value) {
157-
if (is_int($name)) {
158-
$this->params[] = $value;
159-
} else {
160-
$this->params[$name] = $value;
161-
}
162-
}
156+
157+
return $this;
163158
}
164159

160+
if (is_int(key($params))) {
161+
array_push($this->params, ...$params);
162+
163+
return $this;
164+
}
165+
166+
$this->params = [...$this->params, ...$params];
167+
165168
return $this;
166169
}
167170

@@ -1026,7 +1029,7 @@ private function normalizeSelect(array|bool|float|int|string|ExpressionInterface
10261029

10271030
if (is_string($columnDefinition)) {
10281031
if (
1029-
preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_.]+)$/', $columnDefinition, $matches)
1032+
preg_match('/^(.*?)\s+(?i:as\s+)?([\w\-_.]+)$/', $columnDefinition, $matches) === 1
10301033
&& !preg_match('/^\d+$/', $matches[2])
10311034
&& !str_contains($matches[2], '.')
10321035
) {

0 commit comments

Comments
 (0)