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

GroupByCriterion::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
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