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

SmartSleep::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
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;
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 3
    public function __construct(Schedule $schedule)
23
    {
24 3
        $this->schedule = $schedule;
25 3
    }
26
27
    /**
28
     * @param \DateTime $now
29
     *
30
     * @return int
31
     */
32 3
    public function getSleepSeconds(\DateTime $now)
33
    {
34 3
        $rule = $this->schedule->getMatchedRule($now);
35 3
        if ($rule instanceof RuleInterface) {
36 2
            $seconds = $rule->getSeconds();
37
38 2
            return $seconds > 0 ? $seconds : 0;
39
        }
40
41 1
        return 0;
42
    }
43
}
44