Completed
Push — master ( b7fe7e...4bccf1 )
by Peter
01:34
created

SpecificDayRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A isMatched() 0 8 3
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 */
8
9
namespace AnimeDb\SmartSleep\Rule;
10
11
class SpecificDayRule implements HourIntervalRule
12
{
13
    use HourlyIntervalRuleTrait;
14
    use RandSecondsRuleTrait;
15
16
    /**
17
     * @var \DateTime
18
     */
19
    private $day;
20
21
    /**
22
     * @param \DateTime $day
23
     * @param int $start
24
     * @param int $end
25
     * @param int $seconds
26
     */
27 7
    public function __construct(\DateTime $day, $start, $end, $seconds)
28
    {
29 7
        $this->day = clone $day;
30 7
        $this->setStart($start);
31 7
        $this->setEnd($end);
32 7
        $this->setSeconds($seconds);
33 7
    }
34
35
    /**
36
     * @param \DateTime $time
37
     *
38
     * @return bool
39
     */
40 7
    public function isMatched(\DateTime $time)
41
    {
42
        return
43 7
            $this->day->format('Ymd') == $time->format('Ymd') &&
44 7
            $this->start() <= $time->format('G') &&
45 7
            $this->end() > $time->format('G')
46
        ;
47
    }
48
}
49