ArrayAccessible   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 0
cts 32
cp 0
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 8 2
A offsetUnset() 0 4 1
A getIterator() 0 4 1
A toArray() 0 4 1
1
<?php
2
3
namespace Kaylyu\Alipay\Kernel\Support;
4
5
use ArrayAccess;
6
use ArrayIterator;
7
use IteratorAggregate;
8
use Kaylyu\Alipay\Kernel\Contracts\Arrayable;
9
10
/**
11
 * Class ArrayAccessible.
12
 */
13
class ArrayAccessible implements ArrayAccess, IteratorAggregate, Arrayable
14
{
15
    private $array;
16
17
    public function __construct(array $array = [])
18
    {
19
        $this->array = $array;
20
    }
21
22
    public function offsetExists($offset)
23
    {
24
        return array_key_exists($offset, $this->array);
25
    }
26
27
    public function offsetGet($offset)
28
    {
29
        return $this->array[$offset];
30
    }
31
32
    public function offsetSet($offset, $value)
33
    {
34
        if (null === $offset) {
35
            $this->array[] = $value;
36
        } else {
37
            $this->array[$offset] = $value;
38
        }
39
    }
40
41
    public function offsetUnset($offset)
42
    {
43
        unset($this->array[$offset]);
44
    }
45
46
    public function getIterator()
47
    {
48
        return new ArrayIterator($this->array);
49
    }
50
51
    public function toArray()
52
    {
53
        return $this->array;
54
    }
55
}
56