Code Duplication    Length = 35-36 lines in 2 locations

src/Rule/OnceDayRule.php 1 location

@@ 11-46 (lines=36) @@
8
9
namespace AnimeDb\SmartSleep\Rule;
10
11
class OnceDayRule implements Rule
12
{
13
    /**
14
     * @var \DateTime
15
     */
16
    private $time;
17
18
    public function __construct()
19
    {
20
        $this->time = new \DateTimeImmutable(); // default time
21
    }
22
23
    /**
24
     * @param \DateTimeImmutable $time
25
     *
26
     * @return bool
27
     */
28
    public function isMatched(\DateTimeImmutable $time)
29
    {
30
        $this->time = $time; // save current time
31
32
        return true;
33
    }
34
35
    /**
36
     * @return int
37
     */
38
    public function seconds()
39
    {
40
        $offset_time = $this->time;
41
        $offset_time->modify('+1 day')->setTime(0, 0, 0);
42
        $offset = $offset_time->getTimestamp() - $this->time->getTimestamp(); // offset to next day
43
44
        return $offset + rand(0, 86400); // 86400 is a 1 day
45
    }
46
}
47

src/Rule/OnceWeekRule.php 1 location

@@ 11-45 (lines=35) @@
8
9
namespace AnimeDb\SmartSleep\Rule;
10
11
class OnceWeekRule implements Rule
12
{
13
    /**
14
     * @var \DateTime
15
     */
16
    private $time;
17
18
    public function __construct()
19
    {
20
        $this->time = new \DateTimeImmutable(); // default time
21
    }
22
23
    /**
24
     * @param \DateTimeImmutable $time
25
     *
26
     * @return bool
27
     */
28
    public function isMatched(\DateTimeImmutable $time)
29
    {
30
        $this->time = $time; // save current time
31
32
        return true;
33
    }
34
35
    /**
36
     * @return int
37
     */
38
    public function seconds()
39
    {
40
        $offset_time = $this->time->modify('+1 week')->setTime(0, 0, 0);
41
        $offset = $offset_time->getTimestamp() - $this->time->getTimestamp(); // offset to next week
42
43
        return $offset + rand(0, 604800); // 604800 is a 1 week
44
    }
45
}
46