Completed
Push — master ( f2c57a...b4ecb3 )
by Gabriel
02:40
created

Collection::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Waredesk;
4
5
use Iterator;
6
use Countable;
7
use JsonSerializable;
8
use ArrayAccess;
9
10
abstract class Collection implements Iterator, Countable, ArrayAccess, JsonSerializable
11
{
12
    protected $items;
13
    protected $key;
14
15 9
    public function __construct(array $items = [])
16
    {
17 9
        $this->items = $items;
18 9
    }
19
20 1
    public function __clone()
21
    {
22 1
        foreach ($this->items as $key => $item) {
23 1
            $this->items[$key] = clone $item;
24
        }
25 1
    }
26
27 4
    public function reset(): void
28
    {
29 4
        $this->items = [];
30 4
    }
31
32
    public function replace(array $items = []): void
33
    {
34
        $this->items = $items;
35
    }
36
37 9
    public function add($item): void
38
    {
39 9
        $this->items[] = $item;
40 9
    }
41
42 8
    public function first()
43
    {
44 8
        return isset($this->items[0]) ? $this->items[0] : null;
45
    }
46
47
    public function toArray(): array
48
    {
49
        return $this->items;
50
    }
51
52
    public function jsonSerialize(): array
53
    {
54 5
        return array_map(function (JsonSerializable $item) {
55 5
            return $item->jsonSerialize();
56 5
        }, $this->items);
57
    }
58
59 4
    public function count(): int
60
    {
61 4
        return count($this->items);
62
    }
63
64 1
    public function current()
65
    {
66 1
        return current($this->items);
67
    }
68
69 1
    public function next()
70
    {
71 1
        return next($this->items);
72
    }
73
74 1
    public function key(): int
75
    {
76 1
        return key($this->items);
77
    }
78
79 8
    public function valid(): bool
80
    {
81 8
        $key = key($this->items);
82 8
        return ($key !== null && $key !== false);
83
    }
84
85 8
    public function rewind(): void
86
    {
87 8
        reset($this->items);
88 8
    }
89
90
    public function offsetExists($offset): bool
91
    {
92
        return array_key_exists($offset, $this->items);
93
    }
94
95
    public function offsetGet($offset)
96
    {
97
        return $this->items[$offset];
98
    }
99
100
    public function offsetSet($offset, $value): void
101
    {
102
        $this->items[$offset] = $value;
103
    }
104
105 1
    public function offsetUnset($offset): void
106
    {
107 1
        unset($this->items[$offset]);
108 1
    }
109
}
110