Passed
Push — master ( 36df2b...89c2b4 )
by noitran
03:13
created

LimitBy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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 1
    public function __construct($count)
25
    {
26 1
        $this->count = $count;
27 1
    }
28
29
    /**
30
     * @param Builder $model
31
     * @param RepositoryInterface $repository
32
     *
33
     * @return Builder
34
     */
35 1
    public function apply($model, RepositoryInterface $repository): Builder
36
    {
37 1
        if ($this->count) {
38 1
            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