1 | <?php |
||
14 | class HasByNonDependentSubqueryMacro |
||
15 | { |
||
16 | /** |
||
17 | * @var \Illuminate\Database\Eloquent\Builder |
||
18 | */ |
||
19 | protected $query; |
||
20 | |||
21 | /** |
||
22 | * HasByNonDependentSubqueryMacro constructor. |
||
23 | * |
||
24 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
25 | */ |
||
26 | 23 | public function __construct(Builder $query) |
|
30 | |||
31 | /** |
||
32 | * @param string|string[] $relationMethod |
||
33 | * @param callable[]|null[] $constraints |
||
34 | * @return \Illuminate\Database\Eloquent\Builder |
||
35 | */ |
||
36 | 20 | public function has($relationMethod, ?callable ...$constraints): Builder |
|
40 | |||
41 | /** |
||
42 | * @param string|string[] $relationMethod |
||
43 | * @param callable[]|null[] $constraints |
||
44 | * @return \Illuminate\Database\Eloquent\Builder |
||
45 | */ |
||
46 | 1 | public function orHas($relationMethod, ?callable ...$constraints): Builder |
|
47 | { |
||
48 | 1 | return $this->apply($relationMethod, 'orWhereIn', ...$constraints); |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param string|string[] $relationMethod |
||
53 | * @param callable[]|null[] $constraints |
||
54 | * @return \Illuminate\Database\Eloquent\Builder |
||
55 | */ |
||
56 | 1 | public function doesntHave($relationMethod, ?callable ...$constraints): Builder |
|
57 | { |
||
58 | 1 | return $this->apply($relationMethod, 'whereNotIn', ...$constraints); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * @param string|string[] $relationMethod |
||
63 | * @param callable[]|null[] $constraints |
||
64 | * @return \Illuminate\Database\Eloquent\Builder |
||
65 | */ |
||
66 | 1 | public function orDoesntHave($relationMethod, ?callable ...$constraints): Builder |
|
67 | { |
||
68 | 1 | return $this->apply($relationMethod, 'orWhereNotIn', ...$constraints); |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Parse nested constraints and iterate them to apply. |
||
73 | * |
||
74 | * @param string|string[] $relationMethod |
||
75 | * @param string $whereInMethod |
||
76 | * @param callable[]|null[] $constraints |
||
77 | * @return \Illuminate\Database\Eloquent\Builder |
||
78 | */ |
||
79 | 23 | protected function apply($relationMethod, string $whereInMethod, ?callable ...$constraints): Builder |
|
104 | |||
105 | /** |
||
106 | * Apply the current relation as a non-dependent subquery. |
||
107 | * |
||
108 | * @param string $relationMethod |
||
109 | * @param string $whereInMethod |
||
110 | * @param null|callable $constraints |
||
111 | */ |
||
112 | 23 | protected function applyForCurrentRelation(string $relationMethod, string $whereInMethod, callable $constraints): void |
|
136 | } |
||
137 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.