ArrayProxy::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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 5
    public function __construct(array $resource)
17
    {
18 5
        $this->resource = $resource;
19 5
    }
20
21
    public static function map(array $resources)
22
    {
23 1
        return array_map(function (array $resource) {
24 1
            return new static($resource);
25 1
        }, $resources);
26
    }
27
28 3
    public function __get(string $property)
29
    {
30 3
        return $this->get($property);
31
    }
32
33
    public function offsetExists($offset)
34
    {
35
        return true;
36
    }
37
38 2
    public function offsetGet($offset)
39
    {
40 2
        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 5
    private function get($property)
59
    {
60 5
        if (array_key_exists($property, $this->resource)) {
61 3
            return $this->resource[$property];
62
        }
63
64 2
        return NullProxy::instance();
65
    }
66
}
67