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
Push — master ( f4b1b2...f12cf1 )
by Sebastian
02:21
created

TimeRange   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A fromString() 0 10 2
A start() 0 4 1
A end() 0 4 1
A spillsOverToNextDay() 0 4 1
A containsTime() 0 12 4
A overlaps() 0 4 2
A format() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace Spatie\OpeningHours;
4
5
use Spatie\OpeningHours\Exceptions\InvalidTimeRangeString;
6
7
class TimeRange
8
{
9
    /** @var \Spatie\OpeningHours\Time */
10
    protected $start;
11
12
    /** @var \Spatie\OpeningHours\Time */
13
    protected $end;
14
15
    protected function __construct(Time $start, Time $end)
16
    {
17
        $this->start = $start;
18
        $this->end = $end;
19
    }
20
21
    public static function fromString(string $string): self
22
    {
23
        $times = explode('-', $string);
24
25
        if (count($times) !== 2) {
26
            throw InvalidTimeRangeString::forString($string);
27
        }
28
29
        return new self(Time::fromString($times[0]), Time::fromString($times[1]));
30
    }
31
32
    public function start(): Time
33
    {
34
        return $this->start;
35
    }
36
37
    public function end(): Time
38
    {
39
        return $this->end;
40
    }
41
42
    public function spillsOverToNextDay(): bool
43
    {
44
        return $this->end->isBefore($this->start);
45
    }
46
47
    public function containsTime(Time $time): bool
48
    {
49
        if ($this->spillsOverToNextDay()) {
50
            if ($time->isAfter($this->start)) {
51
                return $time->isAfter($this->end);
52
            }
53
54
            return $time->isBefore($this->end);
55
        }
56
57
        return $time->isSameOrAfter($this->start) && $time->isBefore($this->end);
58
    }
59
60
    public function overlaps(TimeRange $timeRange): bool
61
    {
62
        return $this->containsTime($timeRange->start) || $this->containsTime($timeRange->end);
63
    }
64
65
    public function format(string $timeFormat = 'H:i', string $rangeFormat = '%s-%s'): string
66
    {
67
        return sprintf($rangeFormat, $this->start->format($timeFormat), $this->end->format($timeFormat));
68
    }
69
70
    public function __toString(): string
71
    {
72
        return $this->format();
73
    }
74
}
75