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.

IterableImplementation   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetGet() 0 4 1
A offsetSet() 0 10 2
A offsetExists() 0 4 1
A offsetUnset() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
A count() 0 4 1
1
<?php
2
3
namespace Spatie\Period;
4
5
trait IterableImplementation
6
{
7
    protected $position = 0;
8
9
    public function offsetGet($offset)
10
    {
11
        return $this->periods[$offset] ?? null;
0 ignored issues
show
Bug introduced by
The property periods does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
12
    }
13
14
    public function offsetSet($offset, $value)
15
    {
16
        if (is_null($offset)) {
17
            $this->periods[] = $value;
18
19
            return;
20
        }
21
22
        $this->periods[$offset] = $value;
23
    }
24
25
    public function offsetExists($offset)
26
    {
27
        return array_key_exists($offset, $this->periods);
28
    }
29
30
    public function offsetUnset($offset)
31
    {
32
        unset($this->periods[$offset]);
33
    }
34
35
    public function next()
36
    {
37
        $this->position++;
38
    }
39
40
    public function key()
41
    {
42
        return $this->position;
43
    }
44
45
    public function valid()
46
    {
47
        return array_key_exists($this->position, $this->periods);
48
    }
49
50
    public function rewind()
51
    {
52
        $this->position = 0;
53
    }
54
55
    public function count(): int
56
    {
57
        return count($this->periods);
58
    }
59
}
60