Completed
Push — 1.0 ( ba8fdc...8ff026 )
by David
10s
created

CompositeArrayAccess::offsetGet()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Drupal\easy_entity_reader;
4
5
/**
6
 * Composite to read an array or a wrapper.
7
 *
8
 * Class EntityAdapter.
9
 */
10
class CompositeArrayAccess implements \ArrayAccess
11
{
12
    /**
13
     * @var array
14
     */
15
    private $arrays;
16
17
    /**
18
     * @param array $arrays
19
     */
20
    public function __construct(array $arrays)
21
    {
22
        $this->arrays = $arrays;
23
    }
24
25
    /**
26
     * @param $offset
27
     */
28
    public function offsetExists($offset)
29
    {
30
        foreach ($this->arrays as $array) {
31
            if (isset($array[$offset])) {
32
                return true;
33
            }
34
        }
35
        return false;
36
    }
37
38
    /**
39
     * @param $offset
40
     */
41
    public function offsetGet($offset)
42
    {
43
        foreach ($this->arrays as $array) {
44
            if (isset($array[$offset])) {
45
                return $array[$offset];
46
            }
47
        }
48
        throw new \Exception('The index "'.$offset.'" doesn\'t exist');
49
    }
50
51
    /**
52
     * @param $offset
53
     * @param $value
54
     */
55
    public function offsetSet($offset, $value)
56
    {
57
        throw new \Exception('Not supported');
58
    }
59
60
    /**
61
     * @param $offset
62
     */
63
    public function offsetUnset($offset)
64
    {
65
        throw new \Exception('Not supported');
66
    }
67
}
68