Skip to content

Commit ea5eacd

Browse files
committed
refactor: type between query values as array
1 parent f889329 commit ea5eacd

5 files changed

Lines changed: 25 additions & 27 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ private function parseWhereColumnFirst(string $first): array
922922
*
923923
* @throws InvalidArgumentException
924924
*/
925-
public function whereBetween(?string $key = null, $values = null, ?bool $escape = null): static
925+
public function whereBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
926926
{
927927
return $this->whereBetweenHaving('QBWhere', $key, $values, false, 'AND ', $escape);
928928
}
@@ -937,7 +937,7 @@ public function whereBetween(?string $key = null, $values = null, ?bool $escape
937937
*
938938
* @throws InvalidArgumentException
939939
*/
940-
public function orWhereBetween(?string $key = null, $values = null, ?bool $escape = null): static
940+
public function orWhereBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
941941
{
942942
return $this->whereBetweenHaving('QBWhere', $key, $values, false, 'OR ', $escape);
943943
}
@@ -952,7 +952,7 @@ public function orWhereBetween(?string $key = null, $values = null, ?bool $escap
952952
*
953953
* @throws InvalidArgumentException
954954
*/
955-
public function whereNotBetween(?string $key = null, $values = null, ?bool $escape = null): static
955+
public function whereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
956956
{
957957
return $this->whereBetweenHaving('QBWhere', $key, $values, true, 'AND ', $escape);
958958
}
@@ -967,7 +967,7 @@ public function whereNotBetween(?string $key = null, $values = null, ?bool $esca
967967
*
968968
* @throws InvalidArgumentException
969969
*/
970-
public function orWhereNotBetween(?string $key = null, $values = null, ?bool $escape = null): static
970+
public function orWhereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
971971
{
972972
return $this->whereBetweenHaving('QBWhere', $key, $values, true, 'OR ', $escape);
973973
}
@@ -982,7 +982,7 @@ public function orWhereNotBetween(?string $key = null, $values = null, ?bool $es
982982
*
983983
* @throws InvalidArgumentException
984984
*/
985-
public function havingBetween(?string $key = null, $values = null, ?bool $escape = null): static
985+
public function havingBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
986986
{
987987
return $this->whereBetweenHaving('QBHaving', $key, $values, false, 'AND ', $escape);
988988
}
@@ -997,7 +997,7 @@ public function havingBetween(?string $key = null, $values = null, ?bool $escape
997997
*
998998
* @throws InvalidArgumentException
999999
*/
1000-
public function orHavingBetween(?string $key = null, $values = null, ?bool $escape = null): static
1000+
public function orHavingBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
10011001
{
10021002
return $this->whereBetweenHaving('QBHaving', $key, $values, false, 'OR ', $escape);
10031003
}
@@ -1012,7 +1012,7 @@ public function orHavingBetween(?string $key = null, $values = null, ?bool $esca
10121012
*
10131013
* @throws InvalidArgumentException
10141014
*/
1015-
public function havingNotBetween(?string $key = null, $values = null, ?bool $escape = null): static
1015+
public function havingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
10161016
{
10171017
return $this->whereBetweenHaving('QBHaving', $key, $values, true, 'AND ', $escape);
10181018
}
@@ -1027,7 +1027,7 @@ public function havingNotBetween(?string $key = null, $values = null, ?bool $esc
10271027
*
10281028
* @throws InvalidArgumentException
10291029
*/
1030-
public function orHavingNotBetween(?string $key = null, $values = null, ?bool $escape = null): static
1030+
public function orHavingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null): static
10311031
{
10321032
return $this->whereBetweenHaving('QBHaving', $key, $values, true, 'OR ', $escape);
10331033
}
@@ -1050,7 +1050,7 @@ public function orHavingNotBetween(?string $key = null, $values = null, ?bool $e
10501050
*
10511051
* @throws InvalidArgumentException
10521052
*/
1053-
private function whereBetweenHaving(string $qbKey, ?string $key = null, $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null): static
1053+
private function whereBetweenHaving(string $qbKey, ?string $key = null, ?array $values = null, bool $not = false, string $type = 'AND ', ?bool $escape = null): static
10541054
{
10551055
if ($key === null || $key === '') {
10561056
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));

system/Model.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@
4949
* @method $this groupEnd()
5050
* @method $this groupStart()
5151
* @method $this having($key, $value = null, ?bool $escape = null)
52-
* @method $this havingBetween(?string $key = null, $values = null, ?bool $escape = null)
52+
* @method $this havingBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
5353
* @method $this havingGroupEnd()
5454
* @method $this havingGroupStart()
5555
* @method $this havingIn(?string $key = null, $values = null, ?bool $escape = null)
5656
* @method $this havingLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
57-
* @method $this havingNotBetween(?string $key = null, $values = null, ?bool $escape = null)
57+
* @method $this havingNotBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
5858
* @method $this havingNotIn(?string $key = null, $values = null, ?bool $escape = null)
5959
* @method $this join(string $table, string $cond, string $type = '', ?bool $escape = null)
6060
* @method $this like($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
@@ -68,11 +68,11 @@
6868
* @method $this orderBy(string $orderBy, string $direction = '', ?bool $escape = null)
6969
* @method $this orGroupStart()
7070
* @method $this orHaving($key, $value = null, ?bool $escape = null)
71-
* @method $this orHavingBetween(?string $key = null, $values = null, ?bool $escape = null)
71+
* @method $this orHavingBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
7272
* @method $this orHavingGroupStart()
7373
* @method $this orHavingIn(?string $key = null, $values = null, ?bool $escape = null)
7474
* @method $this orHavingLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
75-
* @method $this orHavingNotBetween(?string $key = null, $values = null, ?bool $escape = null)
75+
* @method $this orHavingNotBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
7676
* @method $this orHavingNotIn(?string $key = null, $values = null, ?bool $escape = null)
7777
* @method $this orLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
7878
* @method $this orLikeAny(list<RawSql|string> $fields, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
@@ -81,11 +81,11 @@
8181
* @method $this orNotHavingLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
8282
* @method $this orNotLike($field, string $match = '', string $side = 'both', ?bool $escape = null, bool $insensitiveSearch = false)
8383
* @method $this orWhere($key, $value = null, ?bool $escape = null)
84-
* @method $this orWhereBetween(?string $key = null, $values = null, ?bool $escape = null)
84+
* @method $this orWhereBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
8585
* @method $this orWhereColumn(string $first, string $second, ?bool $escape = null)
8686
* @method $this orWhereExists($subquery)
8787
* @method $this orWhereIn(?string $key = null, $values = null, ?bool $escape = null)
88-
* @method $this orWhereNotBetween(?string $key = null, $values = null, ?bool $escape = null)
88+
* @method $this orWhereNotBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
8989
* @method $this orWhereNotExists($subquery)
9090
* @method $this orWhereNotIn(?string $key = null, $values = null, ?bool $escape = null)
9191
* @method $this select($select = '*', ?bool $escape = null)
@@ -97,11 +97,11 @@
9797
* @method $this when($condition, callable $callback, ?callable $defaultCallback = null)
9898
* @method $this whenNot($condition, callable $callback, ?callable $defaultCallback = null)
9999
* @method $this where($key, $value = null, ?bool $escape = null)
100-
* @method $this whereBetween(?string $key = null, $values = null, ?bool $escape = null)
100+
* @method $this whereBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
101101
* @method $this whereColumn(string $first, string $second, ?bool $escape = null)
102102
* @method $this whereExists($subquery)
103103
* @method $this whereIn(?string $key = null, $values = null, ?bool $escape = null)
104-
* @method $this whereNotBetween(?string $key = null, $values = null, ?bool $escape = null)
104+
* @method $this whereNotBetween(?string $key = null, array<array-key, mixed>|null $values = null, ?bool $escape = null)
105105
* @method $this whereNotExists($subquery)
106106
* @method $this whereNotIn(?string $key = null, $values = null, ?bool $escape = null)
107107
*

tests/system/Database/Builder/GroupTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ public static function provideHavingBetweenInvalidValuesThrowInvalidArgumentExce
195195
{
196196
return [
197197
'null' => [null],
198-
'not array' => ['not array'],
199198
'empty array' => [[]],
200199
'one value' => [[10]],
201200
'three values' => [[10, 20, 30]],

tests/system/Database/Builder/WhereTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,6 @@ public static function provideWhereBetweenInvalidValuesThrowInvalidArgumentExcep
834834
{
835835
return [
836836
'null' => [null],
837-
'not array' => ['not array'],
838837
'empty array' => [[]],
839838
'one value' => [['2026-01-01']],
840839
'three values' => [

user_guide_src/source/database/query_builder.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ Class Reference
18611861
If ``$first`` does not end with a supported operator, ``=`` is used as the comparison operator.
18621862
Supported operators are ``=``, ``!=``, ``<>``, ``<``, ``>``, ``<=``, and ``>=``.
18631863

1864-
.. php:method:: whereBetween([$key = null[, $values = null[, $escape = null]]])
1864+
.. php:method:: whereBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
18651865
18661866
:param string $key: Name of field to examine
18671867
:param array $values: Two values defining the inclusive range
@@ -1871,7 +1871,7 @@ Class Reference
18711871

18721872
Generates a ``WHERE`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate.
18731873

1874-
.. php:method:: orWhereBetween([$key = null[, $values = null[, $escape = null]]])
1874+
.. php:method:: orWhereBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
18751875
18761876
:param string $key: The field to search
18771877
:param array $values: Two values defining the inclusive range
@@ -1881,7 +1881,7 @@ Class Reference
18811881

18821882
Generates a ``WHERE`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``OR`` if appropriate.
18831883

1884-
.. php:method:: whereNotBetween([$key = null[, $values = null[, $escape = null]]])
1884+
.. php:method:: whereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
18851885
18861886
:param string $key: Name of field to examine
18871887
:param array $values: Two values defining the inclusive range
@@ -1891,7 +1891,7 @@ Class Reference
18911891

18921892
Generates a ``WHERE`` field ``NOT BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate.
18931893

1894-
.. php:method:: orWhereNotBetween([$key = null[, $values = null[, $escape = null]]])
1894+
.. php:method:: orWhereNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
18951895
18961896
:param string $key: The field to search
18971897
:param array $values: Two values defining the inclusive range
@@ -2100,7 +2100,7 @@ Class Reference
21002100

21012101
Adds a ``HAVING`` clause to a query, separating multiple calls with ``OR``.
21022102

2103-
.. php:method:: havingBetween([$key = null[, $values = null[, $escape = null]]])
2103+
.. php:method:: havingBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
21042104
21052105
:param string $key: Name of field to examine
21062106
:param array $values: Two values defining the inclusive range
@@ -2110,7 +2110,7 @@ Class Reference
21102110

21112111
Generates a ``HAVING`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate.
21122112

2113-
.. php:method:: orHavingBetween([$key = null[, $values = null[, $escape = null]]])
2113+
.. php:method:: orHavingBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
21142114
21152115
:param string $key: The field to search
21162116
:param array $values: Two values defining the inclusive range
@@ -2120,7 +2120,7 @@ Class Reference
21202120

21212121
Generates a ``HAVING`` field ``BETWEEN`` minimum and maximum value SQL query, joined with ``OR`` if appropriate.
21222122

2123-
.. php:method:: havingNotBetween([$key = null[, $values = null[, $escape = null]]])
2123+
.. php:method:: havingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
21242124
21252125
:param string $key: Name of field to examine
21262126
:param array $values: Two values defining the inclusive range
@@ -2130,7 +2130,7 @@ Class Reference
21302130

21312131
Generates a ``HAVING`` field ``NOT BETWEEN`` minimum and maximum value SQL query, joined with ``AND`` if appropriate.
21322132

2133-
.. php:method:: orHavingNotBetween([$key = null[, $values = null[, $escape = null]]])
2133+
.. php:method:: orHavingNotBetween(?string $key = null, ?array $values = null, ?bool $escape = null)
21342134
21352135
:param string $key: The field to search
21362136
:param array $values: Two values defining the inclusive range

0 commit comments

Comments
 (0)