IteratorTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 62
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A key() 0 7 1
A IteratorTrait_unwrap() 0 5 1
A rewind() 0 10 1
A next() 0 10 1
A valid() 0 7 1
A current() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Mcneely\Core\Traits;
6
7
use Generator;
8
use Iterator;
9
use Mcneely\Core\CoreObject;
10
11
/**
12
 * Trait IteratorTrait.
13
 *
14
 * @package Mcneely\Core\Traits
15
 *
16
 * @method mixed setCoreObject_CoreTrait($object = null)
17
 * @method CoreObject CoreTrait_getCoreObject()
18
 * @method mixed fireEvents_CoreTrait($eventClassObject, $eventImmediateClass, $eventMethod, $eventTrait)
19
 */
20
trait IteratorTrait
21
{
22 2
    public function key(): string
23
    {
24 2
        $this->CoreTrait_fireEvents($this, __CLASS__, __METHOD__, __TRAIT__);
0 ignored issues
show
Bug introduced by
It seems like CoreTrait_fireEvents() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

24
        $this->/** @scrutinizer ignore-call */ 
25
               CoreTrait_fireEvents($this, __CLASS__, __METHOD__, __TRAIT__);
Loading history...
25
26
        return $this
27 2
            ->IteratorTrait_unwrap()
28 2
            ->key()
29
            ;
30
    }
31
32 3
    protected function IteratorTrait_unwrap(): Iterator
33
    {
34
        return $this
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->CoreTrait_...lass, Generator::class) could return the type Traversable which includes types incompatible with the type-hinted return Iterator. Consider adding an additional type-check to rule them out.
Loading history...
35 3
            ->CoreTrait_getCoreObject()
36 3
            ->unWrap(Iterator::class, Generator::class)
37
            ;
38
    }
39
40 1
    public function current()
41
    {
42 1
        $this->CoreTrait_fireEvents($this, __CLASS__, __METHOD__, __TRAIT__);
43
44
        return $this
45 1
            ->IteratorTrait_unwrap()
46 1
            ->current()
47
            ;
48
    }
49
50 2
    public function next(): self
51
    {
52 2
        $this->CoreTrait_fireEvents($this, __CLASS__, __METHOD__, __TRAIT__);
53
54
        $this
55 2
            ->IteratorTrait_unwrap()
56 2
            ->next()
57
        ;
58
59 2
        return $this;
60
    }
61
62 1
    public function valid(): bool
63
    {
64 1
        $this->CoreTrait_fireEvents($this, __CLASS__, __METHOD__, __TRAIT__);
65
66
        return $this
67 1
            ->IteratorTrait_unwrap()
68 1
            ->valid()
69
            ;
70
    }
71
72 1
    public function rewind(): self
73
    {
74 1
        $this->CoreTrait_fireEvents($this, __CLASS__, __METHOD__, __TRAIT__);
75
76
        $this
77 1
            ->IteratorTrait_unwrap()
78 1
            ->rewind()
79
        ;
80
81 1
        return $this;
82
    }
83
}
84