Total Complexity | 5 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | trait HasEagerLimit |
||
13 | { |
||
14 | use HasLimit; |
||
15 | |||
16 | /** |
||
17 | * Add group limit. |
||
18 | * |
||
19 | * @param int $value |
||
20 | * @return void |
||
21 | */ |
||
22 | 32 | protected function addGroupLimit($value) |
|
23 | { |
||
24 | 32 | $grammar = $this->getEagerLimitGrammar(); |
|
25 | |||
26 | 32 | $sql = $grammar->compileFirstPathSegment( |
|
27 | 32 | $this->related->qualifyColumn( |
|
28 | 32 | $this->related->getPathName() |
|
29 | ) |
||
30 | ); |
||
31 | |||
32 | 32 | $column = new Expression($sql); |
|
33 | |||
34 | 32 | $this->query->groupLimit($value, $column); |
|
35 | |||
36 | 32 | $this->query->getQuery()->addBinding( |
|
37 | 32 | array_fill( |
|
38 | 0, |
||
39 | 32 | substr_count($sql, '?'), |
|
40 | 32 | $this->related->getPathSeparator() |
|
41 | ), |
||
42 | 'groupBy' |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Get the eager limit grammar. |
||
48 | * |
||
49 | * @return \Staudenmeir\EloquentEagerLimitXLaravelAdjacencyList\Query\Grammars\EagerLimitGrammar |
||
50 | */ |
||
51 | 32 | protected function getEagerLimitGrammar() |
|
72 | } |
||
73 | } |
||
74 |