1 | <?php |
||||||||
2 | |||||||||
3 | namespace BiiiiiigMonster\Hasin\Database\Eloquent; |
||||||||
4 | |||||||||
5 | use Closure; |
||||||||
6 | use Illuminate\Database\Eloquent\Builder; |
||||||||
7 | use Illuminate\Database\Eloquent\Relations\BelongsTo; |
||||||||
8 | use Illuminate\Database\Eloquent\Relations\BelongsToMany; |
||||||||
9 | use Illuminate\Database\Eloquent\Relations\HasManyThrough; |
||||||||
10 | use Illuminate\Database\Eloquent\Relations\HasOne; |
||||||||
11 | use Illuminate\Database\Eloquent\Relations\HasOneOrMany; |
||||||||
12 | use Illuminate\Database\Eloquent\Relations\MorphOne; |
||||||||
13 | use Illuminate\Database\Eloquent\Relations\MorphOneOrMany; |
||||||||
14 | use Illuminate\Database\Eloquent\Relations\MorphToMany; |
||||||||
15 | use LogicException; |
||||||||
16 | |||||||||
17 | class RelationMixin |
||||||||
18 | { |
||||||||
19 | public function getRelationExistenceInQuery(): Closure |
||||||||
20 | { |
||||||||
21 | return function (Builder $query, Builder $parentQuery, $columns = ['*']): Builder { |
||||||||
0 ignored issues
–
show
|
|||||||||
22 | $relation = function (Builder $query, Builder $parentQuery, $columns = ['*']): Builder { |
||||||||
23 | return $query->select($columns); |
||||||||
0 ignored issues
–
show
The method
select() does not exist on Illuminate\Database\Eloquent\Builder .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
24 | }; |
||||||||
25 | // basic builder |
||||||||
26 | $belongsTo = function (Builder $query, Builder $parentQuery) use ($relation): Builder { |
||||||||
27 | $columns = $query->qualifyColumn($this->ownerKey); |
||||||||
0 ignored issues
–
show
The method
qualifyColumn() does not exist on Illuminate\Database\Eloquent\Builder .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
28 | |||||||||
29 | $relationQuery = $relation($query, $parentQuery, $columns); |
||||||||
30 | |||||||||
31 | if ($parentQuery->getQuery()->from == $query->getQuery()->from) { |
||||||||
0 ignored issues
–
show
The method
getQuery() does not exist on Illuminate\Database\Eloquent\Builder .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
32 | $relationQuery->from( |
||||||||
33 | $query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash() |
||||||||
0 ignored issues
–
show
The method
getModel() does not exist on Illuminate\Database\Eloquent\Builder .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() The method
getRelationCountHash() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
34 | ); |
||||||||
35 | |||||||||
36 | $relationQuery->getModel()->setTable($hash); |
||||||||
37 | } |
||||||||
38 | |||||||||
39 | return $relationQuery; |
||||||||
40 | }; |
||||||||
41 | $belongsToMany = function (Builder $query, Builder $parentQuery) use ($relation): Builder { |
||||||||
42 | $columns = $this->getExistenceCompareKey(); |
||||||||
0 ignored issues
–
show
The method
getExistenceCompareKey() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
43 | if ($parentQuery->getQuery()->from == $query->getQuery()->from) { |
||||||||
44 | $query->select($columns); |
||||||||
45 | |||||||||
46 | $query->from($this->related->getTable().' as '.$hash = $this->getRelationCountHash()); |
||||||||
0 ignored issues
–
show
The method
from() does not exist on Illuminate\Database\Eloquent\Builder .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
47 | |||||||||
48 | $this->related->setTable($hash); |
||||||||
49 | } |
||||||||
50 | |||||||||
51 | $this->performJoin($query); |
||||||||
0 ignored issues
–
show
The method
performJoin() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
52 | |||||||||
53 | return $relation($query, $parentQuery, $columns); |
||||||||
54 | }; |
||||||||
55 | $hasOneOrMany = function (Builder $query, Builder $parentQuery) use ($relation): Builder { |
||||||||
56 | $columns = $this->getExistenceCompareKey(); |
||||||||
57 | if ($query->getQuery()->from == $parentQuery->getQuery()->from) { |
||||||||
58 | $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash()); |
||||||||
59 | |||||||||
60 | $query->getModel()->setTable($hash); |
||||||||
61 | } |
||||||||
62 | |||||||||
63 | return $relation($query, $parentQuery, $columns); |
||||||||
64 | }; |
||||||||
65 | $hasManyThrough = function (Builder $query, Builder $parentQuery) use ($relation): Builder { |
||||||||
66 | $columns = $this->getQualifiedFirstKeyName(); |
||||||||
0 ignored issues
–
show
The method
getQualifiedFirstKeyName() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
67 | if ($parentQuery->getQuery()->from === $query->getQuery()->from) { |
||||||||
68 | $query->from($query->getModel()->getTable().' as '.$hash = $this->getRelationCountHash()); |
||||||||
69 | |||||||||
70 | $query->join($this->throughParent->getTable(), $this->getQualifiedParentKeyName(), '=', $hash.'.'.$this->secondKey); |
||||||||
0 ignored issues
–
show
The method
getQualifiedParentKeyName() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() The method
join() does not exist on Illuminate\Database\Eloquent\Builder .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
71 | |||||||||
72 | if ($this->throughParentSoftDeletes()) { |
||||||||
0 ignored issues
–
show
The method
throughParentSoftDeletes() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
73 | $query->whereNull($this->throughParent->getQualifiedDeletedAtColumn()); |
||||||||
0 ignored issues
–
show
The method
whereNull() does not exist on Illuminate\Database\Eloquent\Builder .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
74 | } |
||||||||
75 | |||||||||
76 | $query->getModel()->setTable($hash); |
||||||||
77 | |||||||||
78 | return $relation($query, $parentQuery, $columns); |
||||||||
79 | } |
||||||||
80 | |||||||||
81 | if ($parentQuery->getQuery()->from === $this->throughParent->getTable()) { |
||||||||
82 | $table = $this->throughParent->getTable().' as '.$hash = $this->getRelationCountHash(); |
||||||||
83 | |||||||||
84 | $query->join($table, $hash.'.'.$this->secondLocalKey, '=', $this->getQualifiedFarKeyName()); |
||||||||
0 ignored issues
–
show
The method
getQualifiedFarKeyName() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
85 | |||||||||
86 | if ($this->throughParentSoftDeletes()) { |
||||||||
87 | $query->whereNull($hash.'.'.$this->throughParent->getDeletedAtColumn()); |
||||||||
88 | } |
||||||||
89 | |||||||||
90 | return $relation($query, $parentQuery, $columns); |
||||||||
91 | } |
||||||||
92 | |||||||||
93 | $this->performJoin($query); |
||||||||
94 | |||||||||
95 | return $relation($query, $parentQuery, $columns); |
||||||||
96 | }; |
||||||||
97 | // extended builder |
||||||||
98 | $hasOne = function (Builder $query, Builder $parentQuery) use ($hasOneOrMany): Builder { |
||||||||
99 | if ($this->isOneOfMany()) { |
||||||||
0 ignored issues
–
show
The method
isOneOfMany() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
100 | $this->mergeOneOfManyJoinsTo($query); |
||||||||
0 ignored issues
–
show
The method
mergeOneOfManyJoinsTo() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
101 | } |
||||||||
102 | |||||||||
103 | return $hasOneOrMany($query, $parentQuery); |
||||||||
104 | }; |
||||||||
105 | $morphOneOrMany = function (Builder $query, Builder $parentQuery) use ($hasOneOrMany): Builder { |
||||||||
106 | return $hasOneOrMany($query, $parentQuery)->where( |
||||||||
107 | $query->qualifyColumn($this->getMorphType()), |
||||||||
0 ignored issues
–
show
The method
getMorphType() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
108 | $this->morphClass |
||||||||
0 ignored issues
–
show
|
|||||||||
109 | ); |
||||||||
110 | }; |
||||||||
111 | $morphOne = function (Builder $query, Builder $parentQuery) use ($morphOneOrMany): Builder { |
||||||||
112 | if ($this->isOneOfMany()) { |
||||||||
113 | $this->mergeOneOfManyJoinsTo($query); |
||||||||
114 | } |
||||||||
115 | |||||||||
116 | return $morphOneOrMany($query, $parentQuery); |
||||||||
117 | }; |
||||||||
118 | $morphToMany = function (Builder $query, Builder $parentQuery) use ($belongsToMany): Builder { |
||||||||
119 | return $belongsToMany($query, $parentQuery)->where( |
||||||||
120 | $this->qualifyPivotColumn($this->morphType), |
||||||||
0 ignored issues
–
show
The method
qualifyPivotColumn() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
121 | $this->morphClass |
||||||||
0 ignored issues
–
show
|
|||||||||
122 | ); |
||||||||
123 | }; |
||||||||
124 | |||||||||
125 | return match (true) { |
||||||||
126 | // extended relation |
||||||||
127 | $this instanceof HasOne => $hasOne($query, $parentQuery), |
||||||||
128 | $this instanceof MorphOne => $morphOne($query, $parentQuery), |
||||||||
129 | $this instanceof MorphOneOrMany => $morphOneOrMany($query, $parentQuery), |
||||||||
130 | $this instanceof MorphToMany => $morphToMany($query, $parentQuery), |
||||||||
131 | // basic relation |
||||||||
132 | $this instanceof BelongsTo => $belongsTo($query, $parentQuery), |
||||||||
133 | $this instanceof BelongsToMany => $belongsToMany($query, $parentQuery), |
||||||||
134 | $this instanceof HasOneOrMany => $hasOneOrMany($query, $parentQuery), |
||||||||
135 | $this instanceof HasManyThrough => $hasManyThrough($query, $parentQuery), |
||||||||
136 | default => throw new LogicException( |
||||||||
137 | sprintf('%s must be a relationship instance.', $this::class) |
||||||||
138 | ) |
||||||||
139 | }; |
||||||||
140 | }; |
||||||||
141 | } |
||||||||
142 | |||||||||
143 | public function getRelationWhereInKey(): Closure |
||||||||
144 | { |
||||||||
145 | return fn (): string => match (true) { |
||||||||
146 | $this instanceof BelongsTo => $this->getQualifiedForeignKeyName(), |
||||||||
0 ignored issues
–
show
The method
getQualifiedForeignKeyName() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
147 | $this instanceof HasOneOrMany, $this instanceof BelongsToMany => $this->getQualifiedParentKeyName(), |
||||||||
148 | $this instanceof HasManyThrough => $this->getQualifiedLocalKeyName(), |
||||||||
0 ignored issues
–
show
The method
getQualifiedLocalKeyName() does not exist on BiiiiiigMonster\Hasin\Da...\Eloquent\RelationMixin .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||||
149 | default => throw new LogicException( |
||||||||
150 | sprintf('%s must be a relationship instance.', $this::class) |
||||||||
151 | ) |
||||||||
152 | }; |
||||||||
153 | } |
||||||||
154 | } |
||||||||
155 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.