Completed
Push — master ( 3df90d...74371a )
by Vladimir
04:10
created

NullableArray::offsetUnset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/allejo/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Utilities;
9
10
class NullableArray implements \ArrayAccess
11
{
12
    private $data;
13
14 124
    public function __construct(array $arr = [])
15
    {
16 124
        $this->data = $arr;
17 124
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function offsetExists($offset)
23
    {
24
        return true;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 118
    public function offsetGet($offset)
31
    {
32 118
        if (isset($this->data[$offset]))
33 118
        {
34
            return $this->data[$offset];
35
        }
36
37 118
        return null;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 118
    public function offsetSet($offset, $value)
44
    {
45 118
        if ($offset === null) {
46
            return;
47
        }
48
49 118
        $this->data[$offset] = $value;
50 118
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function offsetUnset($offset)
56
    {
57
        if (isset($this->data[$offset]))
58
        {
59
            unset($this->data[$offset]);
60
        }
61
    }
62
}
63