Lines 75.86% 22 / 29
Methods 75.86% 22 / 29
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 where 100.00% 1 / 1 100.00% 1 / 1 1
 whereNested 100.00% 1 / 1 100.00% 1 / 1 1
 whereExists 100.00% 1 / 1 100.00% 1 / 1 1
 whereInQuery 0.00% 0 / 1 0.00% 0 / 1 2
 whereRaw 100.00% 1 / 1 100.00% 1 / 1 1
 whereColumn 100.00% 1 / 1 100.00% 1 / 1 1
 getWheres 100.00% 1 / 1 100.00% 1 / 1 1
 getNestedQuery 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] where n/a 0 / 0 n/a 0 / 0 0
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereEq 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhereEq 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNested n/a 0 / 0 n/a 0 / 0 0
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNestedGroup 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhereNested 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereExists n/a 0 / 0 n/a 0 / 0 0
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNotExists 0.00% 0 / 1 0.00% 0 / 1 2
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhereExists 0.00% 0 / 1 0.00% 0 / 1 2
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhereNotExists 0.00% 0 / 1 0.00% 0 / 1 2
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereInQuery n/a 0 / 0 n/a 0 / 0 0
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNotInQuery 0.00% 0 / 1 0.00% 0 / 1 2
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhereInQuery 0.00% 0 / 1 0.00% 0 / 1 2
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhereNotInQuery 0.00% 0 / 1 0.00% 0 / 1 2
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhere 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereIn 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNotIn 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNull 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNotNull 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereBetween 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNotBetween 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereLike 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] orWhereLike 100.00% 1 / 1 100.00% 1 / 1 1
 [BlueprintAU\Radiant\Concerns\FiltersWhere] whereNotLike 100.00% 1 / 1 100.00% 1 / 1 1
21final class WhereBuilder
22{
23    use FiltersWhere;
24
25    /**
26     * Create a builder over the given query.
27     *
28     * @param  QueryBuilder  $query
29     */
30    public function __construct(
31        private readonly QueryBuilder $query,
32    ) {
33    }
34
35    /**
36     * Add a where clause to the query.
37     *
38     * @param  string|Expression  $column
39     * @param  WhereOperator|string  $operator
40     * @param  mixed  $value
41     * @param  WhereBoolean  $boolean
42     * @return static
43     */
44    public function where(
45        string|Expression $column,
46        WhereOperator|string $operator,
47        mixed $value,
48        WhereBoolean $boolean = WhereBoolean::And,
49    ): static {
50        return new self($this->query->where($column, $operator, $value, $boolean));
51    }
52
53    /**
54     * Add a nested where group to the query.
55     *
56     * @param  callable(WhereBuilder): WhereBuilder  $callback
57     * @param  WhereBoolean  $boolean
58     * @return static
59     */
60    public function whereNested(
61        callable $callback,
62        WhereBoolean $boolean = WhereBoolean::And,
63    ): static {
64        return new self($this->query->whereNested($callback, $boolean));
65    }
66
67    /**
68     * Add an `EXISTS (subquery)` clause to the query.
69     *
70     * @param  QueryBuilder  $query  The existential subquery.
71     * @param  WhereBoolean  $boolean
72     * @param  bool  $negated  True renders `NOT EXISTS`.
73     * @return static
74     */
75    public function whereExists(
76        QueryBuilder $query,
77        WhereBoolean $boolean = WhereBoolean::And,
78        bool $negated = false,
79    ): static {
80        return new self($this->query->whereExists($query, $boolean, $negated));
81    }
82
83    /**
84     * Add a `column IN (subquery)` clause to the query.
85     *
86     * @param  string  $column  The outer column the IN constrains.
87     * @param  QueryBuilder  $query  The single-column value subquery.
88     * @param  WhereBoolean  $boolean
89     * @param  bool  $negated  True renders `NOT IN`.
90     * @return static
91     */
92    public function whereInQuery(
93        string $column,
94        QueryBuilder $query,
95        WhereBoolean $boolean = WhereBoolean::And,
96        bool $negated = false,
97    ): static {
98        return new self($this->query->whereInQuery($column, $query, $boolean, $negated));
99    }
100
101    /**
102     * Add a raw where clause to the query.
103     *
104     * @param  string  $sql
105     * @param  array<int, mixed>  $bindings
106     * @param  WhereBoolean  $boolean
107     * @return static
108     */
109    public function whereRaw(string $sql, array $bindings = [], WhereBoolean $boolean = WhereBoolean::And): static
110    {
111        return new self($this->query->whereRaw($sql, $bindings, $boolean));
112    }
113
114    /**
115     * Add a where clause comparing two columns to the query.
116     *
117     * @param  string  $first
118     * @param  \BlueprintAU\Radiant\Database\Query\Enums\ColumnOperator|string  $operator
119     * @param  string  $second
120     * @param  WhereBoolean  $boolean
121     * @return static
122     */
123    public function whereColumn(string $first, \BlueprintAU\Radiant\Database\Query\Enums\ColumnOperator|string $operator = '=', string $second = '', WhereBoolean $boolean = WhereBoolean::And): static
124    {
125        return new self($this->query->whereColumn($first, $operator, $second, $boolean));
126    }
127
128    /**
129     * Get the where clauses of the query.
130     *
131     * @return list<WhereClause>
132     */
133    public function getWheres(): array
134    {
135        return $this->query->getWheres();
136    }
137
138    /**
139     * Get the underlying query builder.
140     *
141     * @return QueryBuilder
142     */
143    public function getNestedQuery(): QueryBuilder
144    {
145        return $this->query;
146    }
147}

From BlueprintAU\Radiant\Concerns\FiltersWhere

28trait FiltersWhere
29{
30    /**
31     * Add a where clause — the single sink every other filter funnels into.
32     *
33     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
34     * @param  WhereOperator|string  $operator
35     * @param  mixed  $value
36     * @param  WhereBoolean  $boolean
37     * @return static
38     */
39    abstract public function where(
40        string|\BlueprintAU\Radiant\Database\Query\Expression $column,
41        WhereOperator|string $operator,
42        mixed $value,
43        WhereBoolean $boolean = WhereBoolean::And,
44    ): static;
45
46    /**
47     * Add an equality where clause — sugar for
48     * `where($column, '=', $value)`.
49     *
50     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
51     * @param  mixed  $value
52     * @param  WhereBoolean  $boolean
53     * @return static
54     */
55    public function whereEq(
56        string|\BlueprintAU\Radiant\Database\Query\Expression $column,
57        mixed $value,
58        WhereBoolean $boolean = WhereBoolean::And,
59    ): static {
60        return $this->where($column, WhereOperator::Eq, $value, $boolean);
61    }
62
63    /**
64     * Add an OR-connected equality where clause.
65     *
66     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
67     * @param  mixed  $value
68     * @return static
69     */
70    public function orWhereEq(
71        string|\BlueprintAU\Radiant\Database\Query\Expression $column,
72        mixed $value,
73    ): static {
74        return $this->where($column, WhereOperator::Eq, $value, WhereBoolean::Or);
75    }
76
77    /**
78     * Add a nested where group — the second sink.
79     *
80     * @param  callable(WhereBuilder): WhereBuilder  $callback
81     * @param  WhereBoolean  $boolean
82     * @return static
83     */
84    abstract public function whereNested(
85        callable $callback,
86        WhereBoolean $boolean = WhereBoolean::And,
87    ): static;
88
89    /**
90     * Add a nested where group connected by AND.
91     *
92     * @param  callable(WhereBuilder): WhereBuilder  $callback
93     * @return static
94     */
95    public function whereNestedGroup(callable $callback): static
96    {
97        return $this->whereNested($callback, WhereBoolean::And);
98    }
99
100    /**
101     * Add an OR-connected nested where group.
102     *
103     * @param  callable(WhereBuilder): WhereBuilder  $callback
104     * @return static
105     */
106    public function orWhereNested(callable $callback): static
107    {
108        return $this->whereNested($callback, WhereBoolean::Or);
109    }
110
111    /**
112     * Add an `EXISTS (subquery)` clause to the query.
113     *
114     * The subquery is a caller-built builder, typically another model's
115     * `newQuery()` correlated to the outer query via `whereColumn()`.
116     *
117     * @param  QueryBuilder  $query  The existential subquery.
118     * @param  WhereBoolean  $boolean
119     * @param  bool  $negated  True renders `NOT EXISTS`.
120     * @return static
121     */
122    abstract public function whereExists(
123        QueryBuilder $query,
124        WhereBoolean $boolean = WhereBoolean::And,
125        bool $negated = false,
126    ): static;
127
128    /**
129     * Add a `NOT EXISTS (subquery)` clause.
130     *
131     * @param  QueryBuilder  $query  The existential subquery.
132     * @param  WhereBoolean  $boolean
133     * @return static
134     */
135    public function whereNotExists(QueryBuilder $query, WhereBoolean $boolean = WhereBoolean::And): static
136    {
137        return $this->whereExists($query, $boolean, true);
138    }
139
140    /**
141     * Add an OR-connected `EXISTS (subquery)` clause.
142     *
143     * @param  QueryBuilder  $query  The existential subquery.
144     * @return static
145     */
146    public function orWhereExists(QueryBuilder $query): static
147    {
148        return $this->whereExists($query, WhereBoolean::Or);
149    }
150
151    /**
152     * Add an OR-connected `NOT EXISTS (subquery)` clause.
153     *
154     * @param  QueryBuilder  $query  The existential subquery.
155     * @return static
156     */
157    public function orWhereNotExists(QueryBuilder $query): static
158    {
159        return $this->whereExists($query, WhereBoolean::Or, true);
160    }
161
162    /**
163     * Add a `column IN (subquery)` clause to the query.
164     *
165     * The subquery must select exactly one column.
166     *
167     * @param  string  $column  The outer column the IN constrains.
168     * @param  QueryBuilder  $query  The single-column value subquery.
169     * @param  WhereBoolean  $boolean
170     * @param  bool  $negated  True renders `NOT IN`.
171     * @return static
172     */
173    abstract public function whereInQuery(
174        string $column,
175        QueryBuilder $query,
176        WhereBoolean $boolean = WhereBoolean::And,
177        bool $negated = false,
178    ): static;
179
180    /**
181     * Add a `column NOT IN (subquery)` clause.
182     *
183     * @param  string  $column  The outer column the NOT IN constrains.
184     * @param  QueryBuilder  $query  The single-column value subquery.
185     * @param  WhereBoolean  $boolean
186     * @return static
187     */
188    public function whereNotInQuery(string $column, QueryBuilder $query, WhereBoolean $boolean = WhereBoolean::And): static
189    {
190        return $this->whereInQuery($column, $query, $boolean, true);
191    }
192
193    /**
194     * Add an OR-connected `column IN (subquery)` clause.
195     *
196     * @param  string  $column  The outer column the IN constrains.
197     * @param  QueryBuilder  $query  The single-column value subquery.
198     * @return static
199     */
200    public function orWhereInQuery(string $column, QueryBuilder $query): static
201    {
202        return $this->whereInQuery($column, $query, WhereBoolean::Or);
203    }
204
205    /**
206     * Add an OR-connected `column NOT IN (subquery)` clause.
207     *
208     * @param  string  $column  The outer column the NOT IN constrains.
209     * @param  QueryBuilder  $query  The single-column value subquery.
210     * @return static
211     */
212    public function orWhereNotInQuery(string $column, QueryBuilder $query): static
213    {
214        return $this->whereInQuery($column, $query, WhereBoolean::Or, true);
215    }
216
217    /**
218     * Add an `or where` clause.
219     *
220     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
221     * @param  WhereOperator|string  $operator
222     * @param  mixed  $value
223     * @return static
224     */
225    public function orWhere(
226        string|\BlueprintAU\Radiant\Database\Query\Expression $column,
227        WhereOperator|string $operator,
228        mixed $value,
229    ): static {
230        return $this->where($column, $operator, $value, WhereBoolean::Or);
231    }
232
233    /**
234     * Add a `where in` clause.
235     *
236     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
237     * @param  array<int, mixed>  $values
238     * @param  WhereBoolean  $boolean
239     * @return static
240     */
241    public function whereIn(
242        string|\BlueprintAU\Radiant\Database\Query\Expression $column,
243        array $values,
244        WhereBoolean $boolean = WhereBoolean::And,
245    ): static {
246        return $this->where($column, WhereOperator::In, $values, $boolean);
247    }
248
249    /**
250     * Add a `where not in` clause.
251     *
252     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
253     * @param  array<int, mixed>  $values
254     * @param  WhereBoolean  $boolean
255     * @return static
256     */
257    public function whereNotIn(
258        string|\BlueprintAU\Radiant\Database\Query\Expression $column,
259        array $values,
260        WhereBoolean $boolean = WhereBoolean::And,
261    ): static {
262        return $this->where($column, WhereOperator::NotIn, $values, $boolean);
263    }
264
265    /**
266     * Add a `where null` clause.
267     *
268     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
269     * @param  WhereBoolean  $boolean
270     * @return static
271     */
272    public function whereNull(string|\BlueprintAU\Radiant\Database\Query\Expression $column, WhereBoolean $boolean = WhereBoolean::And): static
273    {
274        return $this->where($column, WhereOperator::Null, null, $boolean);
275    }
276
277    /**
278     * Add a `where not null` clause.
279     *
280     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
281     * @param  WhereBoolean  $boolean
282     * @return static
283     */
284    public function whereNotNull(string|\BlueprintAU\Radiant\Database\Query\Expression $column, WhereBoolean $boolean = WhereBoolean::And): static
285    {
286        return $this->where($column, WhereOperator::NotNull, null, $boolean);
287    }
288
289    /**
290     * Add a `where between` clause.
291     *
292     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
293     * @param  array{0: mixed, 1: mixed}  $range
294     * @param  WhereBoolean  $boolean
295     * @return static
296     */
297    public function whereBetween(string|\BlueprintAU\Radiant\Database\Query\Expression $column, array $range, WhereBoolean $boolean = WhereBoolean::And): static
298    {
299        return $this->where($column, WhereOperator::Between, $range, $boolean);
300    }
301
302    /**
303     * Add a `where not between` clause.
304     *
305     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
306     * @param  array{0: mixed, 1: mixed}  $range
307     * @param  WhereBoolean  $boolean
308     * @return static
309     */
310    public function whereNotBetween(string|\BlueprintAU\Radiant\Database\Query\Expression $column, array $range, WhereBoolean $boolean = WhereBoolean::And): static
311    {
312        return $this->where($column, WhereOperator::NotBetween, $range, $boolean);
313    }
314
315    /**
316     * Add a `where like` clause — the pattern is a bound value.
317     *
318     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
319     * @param  string  $pattern
320     * @param  WhereBoolean  $boolean
321     * @return static
322     */
323    public function whereLike(string|\BlueprintAU\Radiant\Database\Query\Expression $column, string $pattern, WhereBoolean $boolean = WhereBoolean::And): static
324    {
325        return $this->where($column, WhereOperator::Like, $pattern, $boolean);
326    }
327
328    /**
329     * Add an OR-connected `where like` clause.
330     *
331     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
332     * @param  string  $pattern
333     * @return static
334     */
335    public function orWhereLike(string|\BlueprintAU\Radiant\Database\Query\Expression $column, string $pattern): static
336    {
337        return $this->where($column, WhereOperator::Like, $pattern, WhereBoolean::Or);
338    }
339
340    /**
341     * Add a `where not like` clause.
342     *
343     * @param  string|\BlueprintAU\Radiant\Database\Query\Expression  $column
344     * @param  string  $pattern
345     * @param  WhereBoolean  $boolean
346     * @return static
347     */
348    public function whereNotLike(string|\BlueprintAU\Radiant\Database\Query\Expression $column, string $pattern, WhereBoolean $boolean = WhereBoolean::And): static
349    {
350        return $this->where($column, WhereOperator::NotLike, $pattern, $boolean);
351    }
352}