Dates   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 47
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 9
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 3
A matchSingleDate() 0 10 2
A matchDateRange() 0 18 4
1
<?php
2
3
namespace PeterColes\Themes\Matchers;
4
5
use RunTimeException;
6
7
class Dates implements MatcherInterface
8
{
9 7
    public function handle($request, $match)
10
    {
11 7
        if (!$match) {
12 1
            throw new RunTimeException('Missing dates for matching');
13
        }
14
15 6
        $date = explode(',', $match);
16
17 6
        if (count($date) == 1) {
18 2
            return $this->matchSingleDate($date[0]);
19
        }
20
21 4
        return $this->matchDateRange($date[0], $date[1]);
22
    }
23
24 2
    protected function matchSingleDate($date)
25
    {
26 2
        $now = date('Y-m-d');
27
28 2
        if ($date < $now) {
29 1
            return false;
30
        }
31
32 1
        return true;
33
    }
34
35 4
    protected function matchDateRange($begin, $end)
36
    {
37 4
        if ($begin > $end) {
38 1
            throw new RunTimeException('End date cannot be before start date');
39
        }
40
41 3
        $now = date('Y-m-d');
42
43 3
        if ($now < $begin) {
44 1
            return false;
45
        }
46
47 2
        if ($end < $now) {
48 1
            return false; 
49
        }
50
51 1
        return true;
52
    }
53
}
54