Total Complexity | 3 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Coverage | 0% |
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 | public function __construct($start, $end) |
||
26 | { |
||
27 | $this->start = $start; |
||
28 | $this->end = $end; |
||
29 | } |
||
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 | public function apply(Builder $builder, Model $model) |
||
39 | { |
||
40 | $start = $this->start; |
||
41 | $end = $this->end; |
||
42 | $builder |
||
43 | ->when(! is_null($start), function ($query) use ($start, $model) { |
||
44 | return $query->where($model->getKeyName(), '>', $start); |
||
45 | }) |
||
46 | ->when(! is_null($end), function ($query) use ($end, $model) { |
||
47 | return $query->where($model->getKeyName(), '<=', $end); |
||
48 | }); |
||
49 | } |
||
50 | |||
51 | public function key(): string |
||
54 | } |
||
55 | } |
||
56 |