Completed
Push — master ( d1ccb9...b41f5f )
by Paul
02:53
created

ArrayAccessTrait   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 49
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A offsetExists() 0 7 1
A offsetUnset() 0 8 1
A offsetGet() 0 7 1
A offsetSet() 0 8 1
A unwrap_ArrayAccessTrait() 0 9 4
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);
0 ignored issues
show
Unused Code introduced by
The call to Mcneely\Core\Traits\Arra...tCoreObject_CoreTrait() has too many arguments starting with $object. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
        $this->/** @scrutinizer ignore-call */ 
62
               setCoreObject_CoreTrait($object);

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.

Loading history...
62
63 2
        return $object;
64
    }
65
}