Iterator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 64
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A prev() 0 3 1
A valid() 0 3 1
A next() 0 3 1
A key() 0 3 1
A current() 0 3 1
A rewind() 0 5 1
1
<?php namespace Mbh\Collection\Traits\Sequenceable\LinkedList;
2
3
/**
4
 * MBHFramework
5
 *
6
 * @link      https://github.com/MBHFramework/mbh-framework
7
 * @copyright Copyright (c) 2017 Ulises Jeremias Cornejo Fandos
8
 * @license   https://github.com/MBHFramework/mbh-framework/blob/master/LICENSE (MIT License)
9
 */
10
11
use Mbh\Collection\Internal\LinkedDataNode;
12
use Traversable;
13
14
trait Iterator
15
{
16
    protected $head;
17
    protected $current;
18
    protected $offset = -1;
19
20
    /**
21
     * @link http://php.net/manual/en/iterator.current.php
22
     * @return mixed
23
     */
24
    public function current()
25
    {
26
        return $this->current->value();
27
    }
28
29
    /**
30
     * @link http://php.net/manual/en/iterator.next.php
31
     * @return void
32
     */
33
    public function next()
34
    {
35
        $this->forward();
36
    }
37
38
    /**
39
     * @return void
40
     */
41
    public function prev()
42
    {
43
        $this->backward();
44
    }
45
46
    /**
47
     * @link http://php.net/manual/en/iterator.key.php
48
     * @return mixed
49
     */
50
    public function key()
51
    {
52
        return $this->offset;
53
    }
54
55
    /**
56
     * @link http://php.net/manual/en/iterator.valid.php
57
     * @return boolean
58
     */
59
    public function valid()
60
    {
61
        return $this->current instanceof LinkedDataNode;
62
    }
63
64
    /**
65
     * @link http://php.net/manual/en/iterator.rewind.php
66
     * @return void
67
     */
68
    public function rewind()
69
    {
70
        $this->current = $this->head;
71
        $this->offset = -1;
72
        $this->forward();
73
    }
74
75
    abstract protected function backward();
76
77
    abstract protected function forward();
78
}
79