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

CompositeArrayAccess   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 58
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A offsetExists() 0 9 3
A offsetGet() 0 9 3
A offsetSet() 0 4 1
A offsetUnset() 0 4 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