OffsetLimitCriterion::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Napp\Core\Dbal\Criteria;
4
5
class OffsetLimitCriterion implements CriterionInterface
6
{
7
    /**
8
     * @var int
9
     */
10
    protected $offset;
11
12
    /**
13
     * @var int
14
     */
15
    protected $limit;
16
17
    /**
18
     * @param int $offset
19
     * @param int $limit
20
     */
21
    public function __construct($offset = 0, $limit = 30)
22
    {
23
        $this->offset = $offset;
24
        $this->limit = $limit;
25
    }
26
27
    /**
28
     * @param \Illuminate\Database\Eloquent\Builder $query
29
     *
30
     * @return \Illuminate\Database\Eloquent\Builder
31
     */
32
    public function apply($query)
33
    {
34
        $query->getQuery()->skip($this->offset);
35
        $query->getQuery()->take($this->limit);
36
37
        return $query;
38
    }
39
}
40