Completed
Push — master ( 3fcb18...671da7 )
by
unknown
06:12 queued 03:04
created

ThisBetweenDatesCriteria::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
namespace App\Ship\Criterias\Eloquent;
4
5
use App\Ship\Parents\Criterias\Criteria;
6
use Carbon\Carbon;
7
use Illuminate\Database\Query\Builder;
8
9
/**
10
 * Class ThisBetweenDatesCriteria
11
 * 
12
 * @author Fabian Widmann <[email protected]>
13
 *
14
 * Retrieves all entities whose date $field's value is between $start and $end.
15
 */
16
class ThisBetweenDatesCriteria extends Criteria
17
{
18
19
    /**
20
     * @var Carbon
21
     */
22
    private $start;
23
24
    /**
25
     * @var Carbon
26
     */
27
    private $end;
28
29
    /**
30
     * @var string
31
     */
32
    private $field;
33
34
35
    public function __construct($field, Carbon $start, Carbon $end)
36
    {
37
        $this->start = $start;
38
        $this->end = $end;
39
        $this->field = $field;
40
    }
41
42
    /**
43
     * Applies the criteria
44
     * 
45
     * @param Builder $model
46
     * @param         $repository
47
     * 
48
     * @return        mixed
49
     */
50
    public function apply($model, $repository)
51
    {
52
        return $model->whereBetween($this->field, [$this->start->toDateString(), $this->end->toDateString()]);
53
    }
54
}
55