Completed
Push — master ( 0ebeda...45d090 )
by Peter
02:31
created

OnceWeekRule::isMatched()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 */
8
namespace AnimeDb\SmartSleep\Rule;
9
10 View Code Duplication
class OnceWeekRule extends RuleBase
11
{
12
    /**
13
     * @var \DateTime
14
     */
15
    protected $time;
16
17 5
    public function __construct()
18
    {
19 5
        $this->time = new \DateTime(); // default time
20 5
    }
21
22
    /**
23
     * @param \DateTime $time
24
     *
25
     * @return bool
26
     */
27 1
    public function isMatched(\DateTime $time)
28
    {
29 1
        $this->time = clone $time; // save current time
30
31 1
        return true;
32
    }
33
34
    /**
35
     * @return int
36
     */
37 2
    public function getSeconds()
38
    {
39 2
        $offset_time = clone $this->time;
40 2
        $offset_time->modify('+1 week 00:00:00');
41 2
        $offset = $offset_time->getTimestamp() - $this->time->getTimestamp(); // offset to next week
42
43 2
        return $offset + rand(0, 604800); // 604800 is a 1 week
44
    }
45
}
46