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::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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