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

LimitBy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

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
    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