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