Completed
Push — master ( 07c194...4e457c )
by Gabriel
02:39
created

Collection::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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 5
    public function __construct(array $items = [])
16
    {
17 5
        $this->items = $items;
18 5
    }
19
20 3
    public function reset()
21
    {
22 3
        $this->items = [];
23 3
    }
24
25
    public function replace(array $items = [])
26
    {
27
        $this->items = $items;
28
    }
29
30 5
    public function add($item)
31
    {
32 5
        $this->items[] = $item;
33 5
    }
34
35 3
    public function first()
36
    {
37 3
        return isset($this->items[0]) ? $this->items[0] : null;
38
    }
39
40
    public function jsonSerialize()
41
    {
42 3
        return array_map(function (JsonSerializable $item) {
43 3
            return $item->jsonSerialize();
44 3
        }, $this->items);
45
    }
46
47 3
    public function count()
48
    {
49 3
        return count($this->items);
50
    }
51
52 1
    public function current()
53
    {
54 1
        return current($this->items);
55
    }
56
57 1
    public function next()
58
    {
59 1
        return next($this->items);
60
    }
61
62 1
    public function key()
63
    {
64 1
        return key($this->items);
65
    }
66
67 5
    public function valid()
68
    {
69 5
        $key = key($this->items);
70 5
        return ($key !== null && $key !== false);
71
    }
72
73 5
    public function rewind()
74
    {
75 5
        reset($this->items);
76 5
    }
77
78
    public function offsetExists($offset): bool
79
    {
80
        return array_key_exists($offset, $this->items);
81
    }
82
83
    public function offsetGet($offset)
84
    {
85
        return $this->items[$offset];
86
    }
87
88
    public function offsetSet($offset, $value)
89
    {
90
        $this->items[$offset] = $value;
91
    }
92
93 1
    public function offsetUnset($offset)
94
    {
95 1
        unset($this->items[$offset]);
96 1
    }
97
}
98