SmartSleep   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 32
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sleepForSeconds() 0 11 3
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