Passed
Push — master ( e7b285...ac21bd )
by noitran
02:40
created

LimitBy::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Noitran\Repositories\Criteria;
4
5
use Noitran\Repositories\Contracts\Criteria\CriteriaInterface;
6
use Noitran\Repositories\Contracts\Repository\RepositoryInterface;
7
use Illuminate\Database\Eloquent\Builder;
8
9
/**
10
 * Class LimitBy.
11
 */
12
class LimitBy implements CriteriaInterface
13
{
14
    /**
15
     * @var string
16
     */
17
    protected $count;
18
19
    /**
20
     * LimitBy constructor.
21
     *
22
     * @param $count
23
     */
24
    public function __construct($count)
25
    {
26
        $this->count = $count;
27
    }
28
29
    /**
30
     * @param Builder $model
31
     * @param RepositoryInterface $repository
32
     *
33
     * @return Builder
34
     */
35
    public function apply($model, RepositoryInterface $repository): Builder
36
    {
37
        if ($this->count) {
38
            return $model->limit($this->count);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $model->limit($this->count) could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
39
        }
40
41
        return $model;
42
    }
43
}
44