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 ( 5f72cb...f6c114 )
by Kyle
12s queued 11s
created

TimeRange::fromList()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.5386
c 0
b 0
f 0
cc 7
nc 12
nop 1
1
<?php
2
3
namespace Spatie\OpeningHours;
4
5
use Spatie\OpeningHours\Exceptions\InvalidTimeRangeList;
6
use Spatie\OpeningHours\Exceptions\InvalidTimeRangeString;
7
8
class TimeRange
9
{
10
    /** @var \Spatie\OpeningHours\Time */
11
    protected $start;
12
13
    /** @var \Spatie\OpeningHours\Time */
14
    protected $end;
15
16
    protected function __construct(Time $start, Time $end)
17
    {
18
        $this->start = $start;
19
        $this->end = $end;
20
    }
21
22
    public static function fromString(string $string): self
23
    {
24
        $times = explode('-', $string);
25
26
        if (count($times) !== 2) {
27
            throw InvalidTimeRangeString::forString($string);
28
        }
29
30
        return new self(Time::fromString($times[0]), Time::fromString($times[1]));
31
    }
32
33
    public static function fromList(array $ranges): self
34
    {
35
        if (count($ranges) === 0) {
36
            throw InvalidTimeRangeList::create();
37
        }
38
39
        foreach ($ranges as $range) {
40
            if (! ($range instanceof self)) {
41
                throw InvalidTimeRangeList::create();
42
            }
43
        }
44
45
        $start = $ranges[0]->start();
46
        $end = $ranges[0]->end();
47
48
        foreach (array_slice($ranges, 1) as $range) {
49
            $rangeStart = $range->start();
50
            if ($rangeStart->format('Gi') < $start->format('Gi')) {
51
                $start = $rangeStart;
52
            }
53
            $rangeEnd = $range->end();
54
            if ($rangeEnd->format('Gi') > $end->format('Gi')) {
55
                $end = $rangeEnd;
56
            }
57
        }
58
59
        return new self($start, $end);
60
    }
61
62
    public function start(): Time
63
    {
64
        return $this->start;
65
    }
66
67
    public function end(): Time
68
    {
69
        return $this->end;
70
    }
71
72
    public function spillsOverToNextDay(): bool
73
    {
74
        return $this->end->isBefore($this->start);
0 ignored issues
show
Documentation introduced by
$this->start is of type object<Spatie\OpeningHours\Time>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
75
    }
76
77
    public function containsTime(Time $time): bool
78
    {
79
        if ($this->spillsOverToNextDay()) {
80
            if ($time->isSameOrAfter($this->start)) {
0 ignored issues
show
Documentation introduced by
$this->start is of type object<Spatie\OpeningHours\Time>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
                return $time->isAfter($this->end);
0 ignored issues
show
Documentation introduced by
$this->end is of type object<Spatie\OpeningHours\Time>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
            }
83
84
            return $time->isBefore($this->end);
0 ignored issues
show
Documentation introduced by
$this->end is of type object<Spatie\OpeningHours\Time>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
        }
86
87
        return $time->isSameOrAfter($this->start) && $time->isBefore($this->end);
0 ignored issues
show
Documentation introduced by
$this->start is of type object<Spatie\OpeningHours\Time>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$this->end is of type object<Spatie\OpeningHours\Time>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
88
    }
89
90
    public function overlaps(self $timeRange): bool
91
    {
92
        return $this->containsTime($timeRange->start) || $this->containsTime($timeRange->end);
93
    }
94
95
    public function format(string $timeFormat = 'H:i', string $rangeFormat = '%s-%s'): string
96
    {
97
        return sprintf($rangeFormat, $this->start->format($timeFormat), $this->end->format($timeFormat));
98
    }
99
100
    public function __toString(): string
101
    {
102
        return $this->format();
103
    }
104
}
105