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

OnceDayRule::seconds()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 8
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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 View Code Duplication
class OnceDayRule implements Rule
12
{
13
    /**
14
     * @var \DateTime
15
     */
16
    private $time;
17
18 2
    public function __construct()
19
    {
20 2
        $this->time = new \DateTime(); // default time
21 2
    }
22
23
    /**
24
     * @param \DateTime $time
25
     *
26
     * @return bool
27
     */
28 1
    public function isMatched(\DateTime $time)
29
    {
30 1
        $this->time = clone $time; // save current time
31
32 1
        return true;
33
    }
34
35
    /**
36
     * @return int
37
     */
38 2
    public function seconds()
39
    {
40 2
        $offset_time = clone $this->time;
41 2
        $offset_time->modify('+1 day')->setTime(0, 0, 0);
42 2
        $offset = $offset_time->getTimestamp() - $this->time->getTimestamp(); // offset to next day
43
44 2
        return $offset + rand(0, 86400); // 86400 is a 1 day
45
    }
46
}
47