From ea5eacdea8825eae47890b33239f70ce9f0f8ea2 Mon Sep 17 00:00:00 2001 From: michalsn Date: Thu, 11 Jun 2026 19:31:53 +0200 Subject: [PATCH] refactor: type between query values as array --- system/Database/BaseBuilder.php | 18 +++++++++--------- system/Model.php | 16 ++++++++-------- tests/system/Database/Builder/GroupTest.php | 1 - tests/system/Database/Builder/WhereTest.php | 1 - .../source/database/query_builder.rst | 16 ++++++++-------- 5 files changed, 25 insertions(+), 27 deletions(-) diff --git a/system/Database/BaseBuilder.php b/system/Database/BaseBuilder.php index 6cf8b56a5154..9d504e926663 100644 --- a/system/Database/BaseBuilder.php +++ b/system/Database/BaseBuilder.php @@ -922,7 +922,7 @@ private function parseWhereColumnFirst(string $first): array * * @throws InvalidArgumentException */ - public function whereBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function whereBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBWhere', $key, $values, false, 'AND ', $escape); } @@ -937,7 +937,7 @@ public function whereBetween(?string $key = null, $values = null, ?bool $escape * * @throws InvalidArgumentException */ - public function orWhereBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function orWhereBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBWhere', $key, $values, false, 'OR ', $escape); } @@ -952,7 +952,7 @@ public function orWhereBetween(?string $key = null, $values = null, ?bool $escap * * @throws InvalidArgumentException */ - public function whereNotBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function whereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBWhere', $key, $values, true, 'AND ', $escape); } @@ -967,7 +967,7 @@ public function whereNotBetween(?string $key = null, $values = null, ?bool $esca * * @throws InvalidArgumentException */ - public function orWhereNotBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function orWhereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBWhere', $key, $values, true, 'OR ', $escape); } @@ -982,7 +982,7 @@ public function orWhereNotBetween(?string $key = null, $values = null, ?bool $es * * @throws InvalidArgumentException */ - public function havingBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function havingBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBHaving', $key, $values, false, 'AND ', $escape); } @@ -997,7 +997,7 @@ public function havingBetween(?string $key = null, $values = null, ?bool $escape * * @throws InvalidArgumentException */ - public function orHavingBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function orHavingBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBHaving', $key, $values, false, 'OR ', $escape); } @@ -1012,7 +1012,7 @@ public function orHavingBetween(?string $key = null, $values = null, ?bool $esca * * @throws InvalidArgumentException */ - public function havingNotBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function havingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBHaving', $key, $values, true, 'AND ', $escape); } @@ -1027,7 +1027,7 @@ public function havingNotBetween(?string $key = null, $values = null, ?bool $esc * * @throws InvalidArgumentException */ - public function orHavingNotBetween(?string $key = null, $values = null, ?bool $escape = null): static + public function orHavingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static { return $this->whereBetweenHaving('QBHaving', $key, $values, true, 'OR ', $escape); } @@ -1050,7 +1050,7 @@ public function orHavingNotBetween(?string $key = null, $values = null, ?bool $e * * @throws InvalidArgumentException */ - private function whereBetweenHaving(string $qbKey, ?string $key = null, $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null): static + private function whereBetweenHaving(string $qbKey, ?string $key = null, ?array $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null): static { if ($key === null || $key === '') { throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function'])); diff --git a/system/Model.php b/system/Model.php index bc43b1db4bc7..4d54b73a70ea 100644 --- a/system/Model.php +++ b/system/Model.php @@ -49,12 +49,12 @@ * @method $this groupEnd() * @method $this groupStart() * @method $this having($key, $value = null, ?bool $escape = null) - * @method $this havingBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this havingBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this havingGroupEnd() * @method $this havingGroupStart() * @method $this havingIn(?string $key = null, $values = null, ?bool $escape = null) * @method $this havingLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false) - * @method $this havingNotBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this havingNotBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this havingNotIn(?string $key = null, $values = null, ?bool $escape = null) * @method $this join(string $table, string $cond, string $type = '', ?bool $escape = null) * @method $this like($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false) @@ -68,11 +68,11 @@ * @method $this orderBy(string $orderBy, string $direction = '', ?bool $escape = null) * @method $this orGroupStart() * @method $this orHaving($key, $value = null, ?bool $escape = null) - * @method $this orHavingBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this orHavingBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this orHavingGroupStart() * @method $this orHavingIn(?string $key = null, $values = null, ?bool $escape = null) * @method $this orHavingLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false) - * @method $this orHavingNotBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this orHavingNotBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this orHavingNotIn(?string $key = null, $values = null, ?bool $escape = null) * @method $this orLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false) * @method $this orLikeAny(list $fields, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false) @@ -81,11 +81,11 @@ * @method $this orNotHavingLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false) * @method $this orNotLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false) * @method $this orWhere($key, $value = null, ?bool $escape = null) - * @method $this orWhereBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this orWhereBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this orWhereColumn(string $first, string $second, ?bool $escape = null) * @method $this orWhereExists($subquery) * @method $this orWhereIn(?string $key = null, $values = null, ?bool $escape = null) - * @method $this orWhereNotBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this orWhereNotBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this orWhereNotExists($subquery) * @method $this orWhereNotIn(?string $key = null, $values = null, ?bool $escape = null) * @method $this select($select = '*', ?bool $escape = null) @@ -97,11 +97,11 @@ * @method $this when($condition, callable $callback, ?callable $defaultCallback = null) * @method $this whenNot($condition, callable $callback, ?callable $defaultCallback = null) * @method $this where($key, $value = null, ?bool $escape = null) - * @method $this whereBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this whereBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this whereColumn(string $first, string $second, ?bool $escape = null) * @method $this whereExists($subquery) * @method $this whereIn(?string $key = null, $values = null, ?bool $escape = null) - * @method $this whereNotBetween(?string $key = null, $values = null, ?bool $escape = null) + * @method $this whereNotBetween(?string $key = null, array|null $values = null, ?bool $escape = null) * @method $this whereNotExists($subquery) * @method $this whereNotIn(?string $key = null, $values = null, ?bool $escape = null) * diff --git a/tests/system/Database/Builder/GroupTest.php b/tests/system/Database/Builder/GroupTest.php index cc940cf0d07d..91f2bd7d41d2 100644 --- a/tests/system/Database/Builder/GroupTest.php +++ b/tests/system/Database/Builder/GroupTest.php @@ -195,7 +195,6 @@ public static function provideHavingBetweenInvalidValuesThrowInvalidArgumentExce { return [ 'null' => [null], - 'not array' => ['not array'], 'empty array' => [[]], 'one value' => [[10]], 'three values' => [[10, 20, 30]], diff --git a/tests/system/Database/Builder/WhereTest.php b/tests/system/Database/Builder/WhereTest.php index 911d054f548d..b1bdf8ba2875 100644 --- a/tests/system/Database/Builder/WhereTest.php +++ b/tests/system/Database/Builder/WhereTest.php @@ -834,7 +834,6 @@ public static function provideWhereBetweenInvalidValuesThrowInvalidArgumentExcep { return [ 'null' => [null], - 'not array' => ['not array'], 'empty array' => [[]], 'one value' => [['2026-01-01']], 'three values' => [ diff --git a/user_guide_src/source/database/query_builder.rst b/user_guide_src/source/database/query_builder.rst index f623674aec5e..09316d6d9036 100644 --- a/user_guide_src/source/database/query_builder.rst +++ b/user_guide_src/source/database/query_builder.rst @@ -1861,7 +1861,7 @@ Class Reference If ``$first`` does not end with a supported operator, ``=`` is used as the comparison operator. Supported operators are ``=``, ``!=``, ``<>``, ``<``, ``>``, ``<=``, and ``>=``. - .. php:method:: whereBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: whereBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: Name of field to examine :param array $values: Two values defining the inclusive range @@ -1871,7 +1871,7 @@ Class Reference Generates a ``WHERE`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate. - .. php:method:: orWhereBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: orWhereBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: The field to search :param array $values: Two values defining the inclusive range @@ -1881,7 +1881,7 @@ Class Reference Generates a ``WHERE`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``OR`` if appropriate. - .. php:method:: whereNotBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: whereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: Name of field to examine :param array $values: Two values defining the inclusive range @@ -1891,7 +1891,7 @@ Class Reference Generates a ``WHERE`` field ``NOT BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate. - .. php:method:: orWhereNotBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: orWhereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: The field to search :param array $values: Two values defining the inclusive range @@ -2100,7 +2100,7 @@ Class Reference Adds a ``HAVING`` clause to a query, separating multiple calls with ``OR``. - .. php:method:: havingBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: havingBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: Name of field to examine :param array $values: Two values defining the inclusive range @@ -2110,7 +2110,7 @@ Class Reference Generates a ``HAVING`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate. - .. php:method:: orHavingBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: orHavingBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: The field to search :param array $values: Two values defining the inclusive range @@ -2120,7 +2120,7 @@ Class Reference Generates a ``HAVING`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``OR`` if appropriate. - .. php:method:: havingNotBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: havingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: Name of field to examine :param array $values: Two values defining the inclusive range @@ -2130,7 +2130,7 @@ Class Reference Generates a ``HAVING`` field ``NOT BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate. - .. php:method:: orHavingNotBetween([$key = null[, $values = null[, $escape = null]]]) + .. php:method:: orHavingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null) :param string $key: The field to search :param array $values: Two values defining the inclusive range