ArrayProxy   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 63.64%

Importance

Changes 0
Metric Value
wmc 10
eloc 13
dl 0
loc 57
ccs 14
cts 22
cp 0.6364
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 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