Passed
Pull Request — master (#33)
by Serhii
04:40
created

PageScope::apply()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Matchish\ScoutElasticSearch\Database\Scopes;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Scope;
8
9
class PageScope implements Scope
10
{
11
12
    /**
13
     * @var int
14
     */
15
    private $page;
16
    /**
17
     * @var int
18
     */
19
    private $perPage;
20
21
    /**
22
     * PageScope constructor.
23
     * @param int $page
24
     * @param int $perPage
25
     */
26 13
    public function __construct(int $page, int $perPage)
27
    {
28 13
        $this->page = $page;
29 13
        $this->perPage = $perPage;
30 13
    }
31
32
    /**
33
     * Apply the scope to a given Eloquent query builder.
34
     *
35
     * @param \Illuminate\Database\Eloquent\Builder $builder
36
     * @param \Illuminate\Database\Eloquent\Model $model
37
     * @return void
38
     */
39 12
    public function apply(Builder $builder, Model $model)
40
    {
41 12
        $builder->forPage($this->page, $this->perPage);
42 12
    }
43
}
44