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

LimitBy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 30
ccs 6
cts 7
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 7 2
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