Completed
Pull Request — 1.0 (#1)
by Marc
01:54
created

CompositeArrayAccess::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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
        return isset($this->entity->$offset);
0 ignored issues
show
Bug introduced by
The property entity does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
    }
32
33
    /**
34
     * @param $offset
35
     */
36
    public function offsetGet($offset)
37
    {
38
        foreach ($this->arrays as $array) {
39
            if (isset($array[$offset])) {
40
                return $array[$offset];
41
            }
42
        }
43
        throw new \Exception('The index "'.$offset.'" doesn\'t exist');
44
    }
45
46
    /**
47
     * @param $offset
48
     * @param $value
49
     */
50
    public function offsetSet($offset, $value)
51
    {
52
        throw new \Exception('Not supported');
53
    }
54
55
    /**
56
     * @param $offset
57
     */
58
    public function offsetUnset($offset)
59
    {
60
        throw new \Exception('Not supported');
61
    }
62
}
63