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

NullableArray   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 52.38%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 53
ccs 11
cts 21
cp 0.5238
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetExists() 0 4 1
A offsetSet() 0 8 2
A offsetGet() 0 9 2
A offsetUnset() 0 7 2
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