SmartSleep::__construct()   A
last analyzed

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