GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#144)
by Kyle
01:12
created

DiffTrait::diffInOpenHours()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\OpeningHours\Helpers;
4
5
use DateTimeInterface;
6
7
trait DiffTrait
8
{
9
    private function diffInSeconds(string $stateCheckMethod, string $nextDateMethod, string $skipDateMethod, DateTimeInterface $startDate, DateTimeInterface $endDate): float
10
    {
11
        $time = 0;
12
13
        if ($endDate < $startDate) {
14
            return -$this->diffInSeconds($stateCheckMethod, $nextDateMethod, $skipDateMethod, $endDate, $startDate);
15
        }
16
17
        $date = $startDate;
18
19
        while ($date < $endDate) {
20
            if ($this->$stateCheckMethod($date)) {
21
                $date = $this->$skipDateMethod($date);
22
                continue;
23
            }
24
25
            $nextDate = min($endDate, $this->$nextDateMethod($date));
26
            $time += floatval($nextDate->format('U.u')) - floatval($date->format('U.u'));
27
            $date = $nextDate;
28
        }
29
30
        return $time;
31
    }
32
33
    public function diffInOpenSeconds(DateTimeInterface $startDate, DateTimeInterface $endDate): float
34
    {
35
        return $this->diffInSeconds('isClosedAt', 'nextClose', 'nextOpen', $startDate, $endDate);
36
    }
37
38
    public function diffInOpenMinutes(DateTimeInterface $startDate, DateTimeInterface $endDate): float
39
    {
40
        return $this->diffInOpenSeconds($startDate, $endDate) / 60;
41
    }
42
43
    public function diffInOpenHours(DateTimeInterface $startDate, DateTimeInterface $endDate): float
44
    {
45
        return $this->diffInOpenMinutes($startDate, $endDate) / 60;
46
    }
47
48
    public function diffInClosedSeconds(DateTimeInterface $startDate, DateTimeInterface $endDate): float
49
    {
50
        return $this->diffInSeconds('isOpenAt', 'nextOpen', 'nextClose', $startDate, $endDate);
51
    }
52
53
    public function diffInClosedMinutes(DateTimeInterface $startDate, DateTimeInterface $endDate): float
54
    {
55
        return $this->diffInClosedSeconds($startDate, $endDate) / 60;
56
    }
57
58
    public function diffInClosedHours(DateTimeInterface $startDate, DateTimeInterface $endDate): float
59
    {
60
        return $this->diffInClosedMinutes($startDate, $endDate) / 60;
61
    }
62
}
63