Total Complexity | 3 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
9 | class ChunkScope implements Scope |
||
10 | { |
||
11 | /** |
||
12 | * @var mixed |
||
13 | */ |
||
14 | private $start; |
||
15 | /** |
||
16 | * @var mixed |
||
17 | */ |
||
18 | private $end; |
||
19 | |||
20 | /** |
||
21 | * ChunkScope constructor. |
||
22 | * @param mixed $start |
||
23 | * @param mixed $end |
||
24 | */ |
||
25 | 12 | public function __construct($start, $end) |
|
29 | 12 | } |
|
30 | |||
31 | /** |
||
32 | * Apply the scope to a given Eloquent query builder. |
||
33 | * |
||
34 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
35 | * @param \Illuminate\Database\Eloquent\Model $model |
||
36 | * @return void |
||
37 | */ |
||
38 | 11 | public function apply(Builder $builder, Model $model) |
|
39 | { |
||
40 | 11 | $start = $this->start; |
|
41 | 11 | $end = $this->end; |
|
42 | $builder |
||
43 | ->when(! is_null($start), function ($query) use ($start, $model) { |
||
44 | 9 | return $query->where($model->getKeyName(), '>', $start); |
|
45 | 11 | }) |
|
46 | ->when(! is_null($end), function ($query) use ($end, $model) { |
||
47 | 11 | return $query->where($model->getKeyName(), '<=', $end); |
|
48 | 11 | }); |
|
49 | 11 | } |
|
50 | |||
51 | 11 | public function key() |
|
54 | } |
||
55 | } |
||
56 |