Completed
Push — master ( 340011...d942bb )
by Mads
8s
created

GroupByCriterion::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace Napp\Core\Dbal\Criteria;
4
5
use Illuminate\Support\Arr;
6
7
class GroupByCriterion implements CriterionInterface
8
{
9
    private $groups;
10
11
    public function __construct(...$groups)
12
    {
13
        foreach ($groups as $group) {
14
            $this->groups = array_merge(
15
                (array) $this->groups,
16
                Arr::wrap($group)
17
            );
18
        }
19
    }
20
21
    /**
22
     * @param \Illuminate\Database\Eloquent\Builder $query
23
     * @return \Illuminate\Database\Eloquent\Builder|void
24
     */
25
    public function apply($query)
26
    {
27
        $query->getQuery()->groupBy($this->groups);
28
    }
29
}
30