Passed
Push — 1.x ( 36b118...cb0b9f )
by Ulises Jeremias
02:31
created

Iterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 63
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 rewind() 0 5 1
A next() 0 3 1
A key() 0 3 1
A current() 0 3 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 Traversable;
12
13
trait Iterator
14
{
15
    protected $current;
16
    protected $offset = -1;
17
18
    /**
19
     * @link http://php.net/manual/en/iterator.current.php
20
     * @return mixed
21
     */
22
    public function current()
23
    {
24
        return $this->current->value();
25
    }
26
27
    /**
28
     * @link http://php.net/manual/en/iterator.next.php
29
     * @return void
30
     */
31
    public function next()
32
    {
33
        $this->forward();
34
    }
35
36
    /**
37
     * @return void
38
     */
39
    public function prev()
40
    {
41
        $this->backward();
42
    }
43
44
    /**
45
     * @link http://php.net/manual/en/iterator.key.php
46
     * @return mixed
47
     */
48
    public function key()
49
    {
50
        return $this->offset;
51
    }
52
53
    /**
54
     * @link http://php.net/manual/en/iterator.valid.php
55
     * @return boolean
56
     */
57
    public function valid()
58
    {
59
        return $this->current instanceof LinkedDataNode;
0 ignored issues
show
Bug introduced by
The type Mbh\Collection\Traits\Se...nkedList\LinkedDataNode was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
60
    }
61
62
    /**
63
     * @link http://php.net/manual/en/iterator.rewind.php
64
     * @return void
65
     */
66
    public function rewind()
67
    {
68
        $this->current = $this->head;
0 ignored issues
show
Bug Best Practice introduced by
The property head does not exist on Mbh\Collection\Traits\Se...ble\LinkedList\Iterator. Did you maybe forget to declare it?
Loading history...
69
        $this->offset = -1;
70
        $this->forward();
71
    }
72
73
    abstract protected function backward();
74
75
    abstract protected function forward();
76
}
77