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   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 56
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A diffInSeconds() 0 23 4
A diffInOpenSeconds() 0 4 1
A diffInOpenMinutes() 0 4 1
A diffInOpenHours() 0 4 1
A diffInClosedSeconds() 0 4 1
A diffInClosedMinutes() 0 4 1
A diffInClosedHours() 0 4 1
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