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 ( 1c2af9...c79e2a )
by Brent
01:13
created

PeriodCollection::add()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Spatie\Period;
4
5
use Iterator;
6
use Countable;
7
use ArrayAccess;
8
9
class PeriodCollection implements ArrayAccess, Iterator, Countable
10
{
11
    use IterableImplementation;
12
13
    /** @var \Spatie\Period\Period[] */
14
    protected $periods;
15
16
    public function __construct(Period ...$periods)
17
    {
18
        $this->periods = $periods;
19
    }
20
21
    public function current(): Period
22
    {
23
        return $this->periods[$this->position];
24
    }
25
26
    public function overlapSingle(PeriodCollection $periodCollection): PeriodCollection
27
    {
28
        $overlaps = new PeriodCollection();
29
30
        foreach ($this as $period) {
31
            foreach ($periodCollection as $otherPeriod) {
32
                if (! $period->overlapSingle($otherPeriod)) {
33
                    continue;
34
                }
35
36
                $overlaps[] = $period->overlapSingle($otherPeriod);
37
            }
38
        }
39
40
        return $overlaps;
41
    }
42
43
    public function overlap(PeriodCollection ...$periodCollections): PeriodCollection
44
    {
45
        $overlap = clone $this;
46
47
        foreach ($periodCollections as $periodCollection) {
48
            $overlap = $overlap->overlapSingle($periodCollection);
49
        }
50
51
        return $overlap;
52
    }
53
54
    public function boundaries(): ?Period
55
    {
56
        $start = null;
57
        $end = null;
58
59
        foreach ($this as $period) {
60
            if ($start === null || $start > $period->getIncludedStart()) {
61
                $start = $period->getStart();
62
            }
63
64
            if ($end === null || $end < $period->getIncludedEnd()) {
65
                $end = $period->getEnd();
66
            }
67
        }
68
69
        if (! $start || ! $end) {
70
            return null;
71
        }
72
73
        [$firstPeriod] = $this->periods;
0 ignored issues
show
Bug introduced by
The variable $firstPeriod does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
74
75
        return new Period(
76
            $start,
77
            $end,
78
            $firstPeriod->getPrecisionMask(),
79
            Boundaries::EXCLUDE_NONE
80
        );
81
    }
82
83
    public function gaps(): PeriodCollection
84
    {
85
        $boundaries = $this->boundaries();
86
87
        if (! $boundaries) {
88
            return new PeriodCollection();
89
        }
90
91
        return $boundaries->diff(...$this);
92
    }
93
94
    public function intersect(Period $intersection): PeriodCollection
95
    {
96
        $intersected = new PeriodCollection();
97
98
        foreach ($this as $period) {
99
            $overlap = $intersection->overlapSingle($period);
100
101
            if ($overlap === null) {
102
                continue;
103
            }
104
105
            $intersected[] = $overlap;
106
        }
107
108
        return $intersected;
109
    }
110
111
    public function add(Period ...$periods): PeriodCollection
112
    {
113
        $collection = clone $this;
114
115
        foreach ($periods as $period) {
116
            $collection[] = $period;
117
        }
118
119
        return $collection;
120
    }
121
122
    public function isEmpty(): bool
123
    {
124
        return count($this->periods) === 0;
125
    }
126
}
127