Completed
Pull Request — master (#5)
by Brent
10:41
created

DateBetween   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 53
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A includeBoundaries() 0 6 1
A excludeBoundaries() 0 6 1
A withoutTime() 0 8 1
A passes() 0 6 1
A message() 0 4 1
1
<?php
2
3
namespace Spatie\ValidationRules\Rules;
4
5
use Carbon\Carbon;
6
use Illuminate\Contracts\Validation\Rule;
7
8
class DateBetween implements Rule
9
{
10
    /** @var \Carbon\Carbon */
11
    protected $start;
12
13
    /** @var \Carbon\Carbon */
14
    protected $end;
15
16
    /** @var bool */
17
    protected $orEquals = true;
18
19
    public function __construct(Carbon $start, Carbon $end)
20
    {
21
        $this->start = $start->copy();
22
23
        $this->end = $end->copy();
24
    }
25
26
    public function includeBoundaries(): DateBetween
27
    {
28
        $this->orEquals = true;
29
30
        return $this;
31
    }
32
33
    public function excludeBoundaries(): DateBetween
34
    {
35
        $this->orEquals = false;
36
37
        return $this;
38
    }
39
40
    public function withoutTime(): DateBetween
41
    {
42
        $this->start->startOfDay();
43
44
        $this->end->endOfDay();
45
46
        return $this;
47
    }
48
49
    public function passes($attribute, $value)
50
    {
51
        $date = Carbon::make($value);
52
53
        return $date->between($this->start, $this->end, $this->orEquals);
54
    }
55
56
    public function message()
57
    {
58
        return __('validationRules.date_between');
59
    }
60
}
61