1 | <?php |
||||||
2 | |||||||
3 | namespace Mpyw\ComposhipsEagerLimit; |
||||||
4 | |||||||
5 | use Awobaz\Compoships\Compoships; |
||||||
6 | use Illuminate\Database\Connection; |
||||||
7 | use Illuminate\Database\Eloquent\Builder; |
||||||
8 | use Illuminate\Database\Eloquent\Model; |
||||||
9 | use Mpyw\ComposhipsEagerLimit\Database\Eloquent\Relations\HasMany as MixedHasMany; |
||||||
10 | use Mpyw\ComposhipsEagerLimit\Database\Eloquent\Relations\HasOne as MixedHasOne; |
||||||
11 | use Mpyw\ComposhipsEagerLimit\Database\Query\Builder as MixedBuilder; |
||||||
12 | use Mpyw\ComposhipsEagerLimit\Database\Query\Grammar\MySqlGrammar; |
||||||
13 | use Mpyw\ComposhipsEagerLimit\Database\Query\Grammar\PostgresGrammar; |
||||||
14 | use Mpyw\ComposhipsEagerLimit\Database\Query\Grammar\SQLiteGrammar; |
||||||
15 | use Mpyw\ComposhipsEagerLimit\Database\Query\Grammar\SqlServerGrammar; |
||||||
16 | use RuntimeException; |
||||||
17 | use Staudenmeir\EloquentEagerLimit\HasEagerLimit; |
||||||
18 | |||||||
19 | /** |
||||||
20 | * Trait ComposhipsEagerLimit |
||||||
21 | * |
||||||
22 | * @mixin \Illuminate\Database\Eloquent\Model |
||||||
23 | */ |
||||||
24 | trait ComposhipsEagerLimit |
||||||
25 | { |
||||||
26 | use Compoships, HasEagerLimit; |
||||||
27 | |||||||
28 | /** |
||||||
29 | * Get the query grammar. |
||||||
30 | * |
||||||
31 | * @param \Illuminate\Database\Connection $connection |
||||||
32 | * @return \Illuminate\Database\Query\Grammars\Grammar |
||||||
33 | */ |
||||||
34 | 630 | protected function getQueryGrammar(Connection $connection) |
|||||
35 | { |
||||||
36 | 630 | $driver = $connection->getDriverName(); |
|||||
37 | |||||||
38 | 630 | switch ($driver) { |
|||||
39 | 630 | case 'mysql': |
|||||
40 | 252 | return new MySqlGrammar(); |
|||||
41 | 378 | case 'pgsql': |
|||||
42 | 126 | return new PostgresGrammar(); |
|||||
43 | 252 | case 'sqlite': |
|||||
44 | 126 | return new SQLiteGrammar(); |
|||||
45 | 126 | case 'sqlsrv': |
|||||
46 | 126 | return new SqlServerGrammar(); |
|||||
47 | } |
||||||
48 | |||||||
49 | throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore |
||||||
50 | } |
||||||
51 | |||||||
52 | /** |
||||||
53 | * Get a new query builder instance for the connection. |
||||||
54 | * |
||||||
55 | * @return \Illuminate\Database\Query\Builder |
||||||
56 | */ |
||||||
57 | 630 | protected function newBaseQueryBuilder() |
|||||
58 | { |
||||||
59 | 630 | $connection = $this->getConnection(); |
|||||
60 | |||||||
61 | 630 | $grammar = $connection->withTablePrefix($this->getQueryGrammar($connection)); |
|||||
62 | |||||||
63 | 630 | return new MixedBuilder( |
|||||
64 | 630 | $connection, $grammar, $connection->getPostProcessor() |
|||||
65 | ); |
||||||
66 | } |
||||||
67 | |||||||
68 | /** |
||||||
69 | * Instantiate a new HasOne relationship. |
||||||
70 | * |
||||||
71 | * @param \Illuminate\Database\Eloquent\Builder $query |
||||||
72 | * @param \Illuminate\Database\Eloquent\Model $parent |
||||||
73 | * @param array|string $foreignKey |
||||||
74 | * @param array|string $localKey |
||||||
75 | * @return \Mpyw\ComposhipsEagerLimit\Database\Eloquent\Relations\HasOne |
||||||
76 | */ |
||||||
77 | 150 | protected function newHasOne(Builder $query, Model $parent, $foreignKey, $localKey) |
|||||
78 | { |
||||||
79 | 150 | return new MixedHasOne($query, $parent, $foreignKey, $localKey); |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() It seems like
$foreignKey can also be of type array ; however, parameter $foreignKey of Mpyw\ComposhipsEagerLimi...s\HasOne::__construct() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
80 | } |
||||||
81 | |||||||
82 | /** |
||||||
83 | * Instantiate a new HasMany relationship. |
||||||
84 | * |
||||||
85 | * @param \Illuminate\Database\Eloquent\Builder $query |
||||||
86 | * @param \Illuminate\Database\Eloquent\Model $parent |
||||||
87 | * @param array|string $foreignKey |
||||||
88 | * @param array|string $localKey |
||||||
89 | * @return \Mpyw\ComposhipsEagerLimit\Database\Eloquent\Relations\HasMany |
||||||
90 | */ |
||||||
91 | 210 | protected function newHasMany(Builder $query, Model $parent, $foreignKey, $localKey) |
|||||
92 | { |
||||||
93 | 210 | return new MixedHasMany($query, $parent, $foreignKey, $localKey); |
|||||
0 ignored issues
–
show
It seems like
$foreignKey can also be of type array ; however, parameter $foreignKey of Mpyw\ComposhipsEagerLimi...\HasMany::__construct() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() It seems like
$localKey can also be of type array ; however, parameter $localKey of Mpyw\ComposhipsEagerLimi...\HasMany::__construct() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
94 | } |
||||||
95 | } |
||||||
96 |