LimitBy   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Noitran\Repositories\Criteria;
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Noitran\Repositories\Contracts\Criteria\CriteriaInterface;
9
use Noitran\Repositories\Contracts\Repository\RepositoryInterface;
10
11
/**
12
 * Class LimitBy.
13
 */
14
class LimitBy implements CriteriaInterface
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $count;
20
21
    /**
22
     * LimitBy constructor.
23
     *
24 1
     * @param $count
25
     */
26 1
    public function __construct($count)
27 1
    {
28
        $this->count = $count;
29
    }
30
31
    /**
32
     * @param Builder $model
33
     * @param RepositoryInterface $repository
34
     *
35 1
     * @return Builder
36
     */
37 1
    public function apply($model, RepositoryInterface $repository) //: Builder
38 1
    {
39
        if ($this->count) {
40
            return $model->limit($this->count);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $model->limit($this->count) also could return the type Illuminate\Database\Query\Builder which is incompatible with the documented return type Illuminate\Database\Eloquent\Builder.
Loading history...
41
        }
42
43
        return $model;
44
    }
45
}
46