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.
Passed
Push — master ( a3899c...75f671 )
by Brent
03:00
created

Collection   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 99
rs 10
c 0
b 0
f 0
wmc 17

13 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetExists() 0 3 1
A offsetGet() 0 3 2
A __construct() 0 13 2
A offsetUnset() 0 3 1
A set() 0 7 2
A toArray() 0 3 1
A offsetSet() 0 8 2
A key() 0 3 1
A current() 0 3 1
A rewind() 0 3 1
A valid() 0 3 1
A next() 0 3 1
A count() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spatie\Typed;
6
7
use Iterator;
8
use Countable;
9
use ArrayAccess;
10
11
class Collection implements ArrayAccess, Iterator, Countable
12
{
13
    use ValidatesType;
14
15
    /** @var \Spatie\Typed\Type */
16
    private $type;
17
18
    /** @var array */
19
    protected $data = [];
20
21
    /** @var int */
22
    private $position = 0;
23
24
    /**
25
     * @var \Spatie\Typed\Type|array $type
26
     */
27
    public function __construct($type)
28
    {
29
        if ($type instanceof Type) {
30
            $this->type = $type;
31
32
            return;
33
        }
34
35
        $firstValue = reset($type);
36
37
        $this->type = T::infer($firstValue);
38
39
        $this->set($type);
40
    }
41
42
    public function set(array $data): Collection
43
    {
44
        foreach ($data as $item) {
45
            $this[] = $item;
46
        }
47
48
        return $this;
49
    }
50
51
    public function current()
52
    {
53
        return $this->data[$this->position];
54
    }
55
56
    public function offsetGet($offset)
57
    {
58
        return isset($this->data[$offset]) ? $this->data[$offset] : null;
59
    }
60
61
    public function offsetSet($offset, $value)
62
    {
63
        $value = $this->validateType($this->type, $value);
64
65
        if (is_null($offset)) {
66
            $this->data[] = $value;
67
        } else {
68
            $this->data[$offset] = $value;
69
        }
70
    }
71
72
    public function offsetExists($offset)
73
    {
74
        return array_key_exists($offset, $this->data);
75
    }
76
77
    public function offsetUnset($offset)
78
    {
79
        unset($this->data[$offset]);
80
    }
81
82
    public function next()
83
    {
84
        $this->position++;
85
    }
86
87
    public function key()
88
    {
89
        return $this->position;
90
    }
91
92
    public function valid()
93
    {
94
        return array_key_exists($this->position, $this->data);
95
    }
96
97
    public function rewind()
98
    {
99
        $this->position = 0;
100
    }
101
102
    public function toArray(): array
103
    {
104
        return $this->data;
105
    }
106
107
    public function count(): int
108
    {
109
        return count($this->data);
110
    }
111
}
112