Completed
Push — master ( c01f78...0ebeda )
by Peter
02:39
created

SmartSleep::getSleepSeconds()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 11
ccs 0
cts 9
cp 0
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 12
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;
9
10
use AnimeDb\SmartSleep\Rule\RuleInterface;
11
12
class SmartSleep
13
{
14
    /**
15
     * @var Schedule
16
     */
17
    protected $schedule = [];
18
19
    /**
20
     * @param Schedule $schedule
21
     */
22
    public function __construct(Schedule $schedule)
23
    {
24
        $this->schedule = $schedule;
25
    }
26
27
    /**
28
     * @param \DateTime $now
29
     *
30
     * @return int
31
     */
32
    public function getSleepSeconds(\DateTime $now)
33
    {
34
        $rule = $this->schedule->getMatchedRule($now);
35
        if ($rule instanceof RuleInterface) {
36
            $seconds = $rule->getSeconds();
37
38
            return $seconds > 0 ? $seconds : 0;
39
        }
40
41
        return 0;
42
    }
43
}
44