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

SpecificDayRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 4
crap 1
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