1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mcneely\Core\Traits; |
4
|
|
|
|
5
|
|
|
use ArrayIterator; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Trait ArrayAccessTrait |
9
|
|
|
* |
10
|
|
|
* @package Mcneely\Core\Traits |
11
|
|
|
* @method \Mcneely\Core\CoreObject getCoreObject_CoreTrait() |
12
|
|
|
* @method mixed setCoreObject_CoreTrait() |
13
|
|
|
* @method mixed fireEvents_CoreTrait($eventClassObject, $eventImmediateClass, $eventMethod, $eventTrait) |
14
|
|
|
*/ |
15
|
|
|
trait ArrayAccessTrait |
16
|
|
|
{ |
17
|
2 |
|
public function offsetExists($offset) |
18
|
|
|
{ |
19
|
2 |
|
$this->fireEvents_CoreTrait($this, __CLASS__, __METHOD__, __TRAIT__); |
20
|
|
|
|
21
|
2 |
|
$object = $this->unwrap_ArrayAccessTrait(); |
22
|
|
|
|
23
|
2 |
|
return $object->offsetExists($offset); |
24
|
|
|
} |
25
|
|
|
|
26
|
1 |
|
public function offsetGet($offset) |
27
|
|
|
{ |
28
|
1 |
|
$this->fireEvents_CoreTrait($this, __CLASS__, __METHOD__, __TRAIT__); |
29
|
|
|
|
30
|
1 |
|
$object = $this->unwrap_ArrayAccessTrait(); |
31
|
|
|
|
32
|
1 |
|
return $object->offsetGet($offset); |
33
|
|
|
} |
34
|
|
|
|
35
|
1 |
|
public function offsetSet($offset, $value) |
36
|
|
|
{ |
37
|
1 |
|
$this->fireEvents_CoreTrait($this, __CLASS__, __METHOD__, __TRAIT__); |
38
|
|
|
|
39
|
1 |
|
$object = $this->unwrap_ArrayAccessTrait(); |
40
|
1 |
|
$object->offsetSet($offset, $value); |
41
|
|
|
|
42
|
1 |
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
1 |
|
public function offsetUnset($offset) |
46
|
|
|
{ |
47
|
1 |
|
$this->fireEvents_CoreTrait($this, __CLASS__, __METHOD__, __TRAIT__); |
48
|
|
|
|
49
|
1 |
|
$object = $this->unwrap_ArrayAccessTrait(); |
50
|
1 |
|
$object->offsetUnset($offset); |
51
|
|
|
|
52
|
1 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
2 |
|
protected function unwrap_ArrayAccessTrait() { |
56
|
2 |
|
$object = $this->getCoreObject_CoreTrait()->getObject(false); |
57
|
2 |
|
$object = ($object instanceof \IteratorAggregate) ? $object->getIterator() : $object; |
58
|
2 |
|
$object = ($object instanceof \IteratorIterator) ? $object->getInnerIterator() : $object; |
59
|
2 |
|
$object = ($object instanceof \Iterator) ? iterator_to_array($object) : (array) $object; |
60
|
2 |
|
$object = new ArrayIterator($object); |
61
|
2 |
|
$this->setCoreObject_CoreTrait($object); |
|
|
|
|
62
|
|
|
|
63
|
2 |
|
return $object; |
64
|
|
|
} |
65
|
|
|
} |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.