Test Failed
Push — master ( 09956b...564e79 )
by Lukas
02:07
created

ArrayProxy   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 13
dl 0
loc 57
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 5 1
A __construct() 0 3 1
A offsetUnset() 0 2 1
A __get() 0 3 1
A offsetGet() 0 3 1
A get() 0 7 2
A offsetExists() 0 3 1
A getIterator() 0 3 1
A offsetSet() 0 2 1
1
<?php
2
3
namespace Lneicelis\Transformer\ValueObject;
4
5
use ArrayAccess;
6
use IteratorAggregate;
7
8
abstract class ArrayProxy implements ArrayAccess, IteratorAggregate
9
{
10
    /** @var mixed */
11
    private $resource;
12
13
    /**
14
     * @param mixed $resource
15
     */
16
    public function __construct(array $resource)
17
    {
18
        $this->resource = $resource;
19
    }
20
21
    public static function map(array $resources)
22
    {
23
        return array_map(function (array $resource) {
24
            return new static($resource);
25
        }, $resources);
26
    }
27
28
    public function __get(string $property)
29
    {
30
        return $this->get($property);
31
    }
32
33
    public function offsetExists($offset)
34
    {
35
        return true;
36
    }
37
38
    public function offsetGet($offset)
39
    {
40
        return $this->get($offset);
41
    }
42
43
    public function offsetSet($offset, $value)
44
    {
45
46
    }
47
48
    public function offsetUnset($offset)
49
    {
50
51
    }
52
53
    public function getIterator()
54
    {
55
        return $this->resource;
56
    }
57
58
    private function get($property)
59
    {
60
        if (array_key_exists($this->resource, $this->resource)) {
61
            $this->resource[$property];
62
        }
63
64
        return NullProxy::instance();
65
    }
66
}
67