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 (#36)
by Sebastian
02:03
created

OpeningHoursForDay::map()   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 1
1
<?php
2
3
namespace Spatie\OpeningHours;
4
5
use Countable;
6
use ArrayAccess;
7
use ArrayIterator;
8
use IteratorAggregate;
9
use Spatie\OpeningHours\Helpers\Arr;
10
use Spatie\OpeningHours\Exceptions\OverlappingTimeRanges;
11
12
class OpeningHoursForDay implements ArrayAccess, Countable, IteratorAggregate
13
{
14
    /** @var \Spatie\OpeningHours\TimeRange[] */
15
    protected $openingHours = [];
16
17
    public static function fromStrings(array $strings)
18
    {
19
        $openingHoursForDay = new static();
20
21
        $timeRanges = Arr::map($strings, function ($string) {
22
            return TimeRange::fromString($string);
23
        });
24
25
        $openingHoursForDay->guardAgainstTimeRangeOverlaps($timeRanges);
26
27
        $openingHoursForDay->openingHours = $timeRanges;
28
29
        return $openingHoursForDay;
30
    }
31
32
    public function isOpenAt(Time $time)
33
    {
34
        foreach ($this->openingHours as $timeRange) {
35
            if ($timeRange->containsTime($time)) {
36
                return true;
37
            }
38
        }
39
40
        return false;
41
    }
42
43
    public function nextOpen(Time $time)
44
    {
45
        foreach ($this->openingHours as $timeRange) {
46
            if ($nextOpen = $this->findNextOpenInWorkingHours($time, $timeRange)) {
47
                return $nextOpen;
48
            }
49
50
            if ($nextOpen = $this->findNextOpenInFreeTime($time, $timeRange)) {
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $nextOpen is correct as $this->findNextOpenInFreeTime($time, $timeRange) (which targets Spatie\OpeningHours\Open...indNextOpenInFreeTime()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
51
                return $nextOpen;
52
            }
53
        }
54
55
        return false;
56
    }
57
58
    protected function findNextOpenInWorkingHours(Time $time, TimeRange $timeRange)
59
    {
60
        if ($timeRange->containsTime($time) && next($timeRange) !== $timeRange) {
61
            return next($timeRange);
62
        }
63
    }
64
65
    protected function findNextOpenInFreeTime(Time $time, TimeRange $timeRange, TimeRange &$prevTimeRange = null)
66
    {
67
        $timeOffRange = $prevTimeRange ?
68
            TimeRange::fromString($prevTimeRange->end().'-'.$timeRange->start()) :
69
            TimeRange::fromString('00:00-'.$timeRange->start());
70
71
        if ($timeOffRange->containsTime($time)) {
72
            return $timeRange->start();
73
        }
74
75
        $prevTimeRange = $timeRange;
76
    }
77
78
    public function offsetExists($offset): bool
79
    {
80
        return isset($this->openingHours[$offset]);
81
    }
82
83
    public function offsetGet($offset)
84
    {
85
        return $this->openingHours[$offset];
86
    }
87
88
    public function offsetSet($offset, $value)
89
    {
90
        throw new \Exception();
91
    }
92
93
    public function offsetUnset($offset)
94
    {
95
        unset($this->openingHours[$offset]);
96
    }
97
98
    public function count(): int
99
    {
100
        return count($this->openingHours);
101
    }
102
103
    public function getIterator()
104
    {
105
        return new ArrayIterator($this->openingHours);
106
    }
107
108
    public function isEmpty(): bool
109
    {
110
        return empty($this->openingHours);
111
    }
112
113
    public function map(callable $callback): array
114
    {
115
        return Arr::map($this->openingHours, $callback);
116
    }
117
118
    protected function guardAgainstTimeRangeOverlaps(array $openingHours)
119
    {
120
        foreach (Arr::createUniquePairs($openingHours) as $timeRanges) {
121
            if ($timeRanges[0]->overlaps($timeRanges[1])) {
122
                throw OverlappingTimeRanges::forRanges($timeRanges[0], $timeRanges[1]);
123
            }
124
        }
125
    }
126
}
127