ArrayAccessible::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Freyo\ApiGateway\Kernel\Support;
4
5
use ArrayAccess;
6
use ArrayIterator;
7
use Freyo\ApiGateway\Kernel\Contracts\Arrayable;
8
use IteratorAggregate;
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