| 1 | <?php |
||
| 2 | |||
| 3 | namespace Mpyw\ComposhipsEagerLimit\Database\Query\Concerns; |
||
| 4 | |||
| 5 | use Staudenmeir\EloquentEagerLimit\Traits\BuildsGroupLimitQueries; |
||
| 6 | |||
| 7 | /** |
||
| 8 | * Trait BuildsGroupLimitQueriesByMultipleColumnPartition |
||
| 9 | * |
||
| 10 | * @mixin \Illuminate\Database\Query\Builder |
||
| 11 | */ |
||
| 12 | trait BuildsGroupLimitQueriesByMultipleColumnPartition |
||
| 13 | { |
||
| 14 | use BuildsGroupLimitQueries; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Execute the query as a "select" statement. |
||
| 18 | * |
||
| 19 | * @param array $columns |
||
| 20 | * @return \Illuminate\Support\Collection |
||
| 21 | */ |
||
| 22 | public function get($columns = ['*']) |
||
| 23 | { |
||
| 24 | $items = parent::get($columns); |
||
| 25 | |||
| 26 | if (!$this->groupLimit) { |
||
|
0 ignored issues
–
show
|
|||
| 27 | return $items; |
||
| 28 | } |
||
| 29 | |||
| 30 | $keys = ['laravel_row']; |
||
| 31 | |||
| 32 | if (is_array($this->groupLimit['column'])) { |
||
| 33 | foreach ($this->groupLimit['column'] as $i => $column) { |
||
| 34 | $keys[] = "@laravel_partition_$i := " . $this->grammar->wrap(last(explode('.', $column))); |
||
| 35 | $keys[] = "@laravel_partition_$i := " . $this->grammar->wrap('pivot_' . last(explode('.', $column))); |
||
| 36 | } |
||
| 37 | } else { |
||
| 38 | $keys[] = '@laravel_partition := ' . $this->grammar->wrap(last(explode('.', $this->groupLimit['column']))); |
||
| 39 | $keys[] = '@laravel_partition := ' . $this->grammar->wrap('pivot_' . last(explode('.', $this->groupLimit['column']))); |
||
| 40 | } |
||
| 41 | |||
| 42 | foreach ($items as $item) { |
||
| 43 | foreach ($keys as $key) { |
||
| 44 | unset($item->$key); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | return $items; |
||
| 49 | } |
||
| 50 | } |
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.