Passed
Push — master ( 1173f0...070f3f )
by Nate
13:41
created

AbstractIterator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 73
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 4 1
A next() 0 4 1
A key() 0 4 1
A valid() 0 4 1
A rewind() 0 4 1
1
<?php
2
/*
3
 * Copyright (c) Nate Brunette.
4
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
5
 */
6
7
namespace Tebru\Gson\Internal;
8
9
use Iterator;
10
11
/**
12
 * Class AbstractIterator
13
 *
14
 * @author Nate Brunette <[email protected]>
15
 */
16
abstract class AbstractIterator implements Iterator
17
{
18
    /**
19
     * Queue of elements to be iterated
20
     *
21
     * @var array
22
     */
23
    protected $queue = [];
24
25
    /**
26
     * Total number of elements in queue
27
     *
28
     * @var int
29
     */
30
    protected $total = 0;
31
32
    /**
33
     * Cursor position
34
     *
35
     * @var int
36
     */
37
    protected $iterated = 0;
38
39
    /**
40
     * Return the current element
41
     *
42
     * @return mixed
43
     */
44 3
    public function current()
45
    {
46 3
        return $this->queue[$this->iterated][1];
47
    }
48
49
    /**
50
     * Move forward to next element
51
     *
52
     * @return void
53
     */
54 10
    public function next(): void
55
    {
56 10
        $this->iterated++;
57 10
    }
58
59
    /**
60
     * Return the key of the current element
61
     *
62
     * @return string
63
     */
64 7
    public function key(): string
65
    {
66 7
        return $this->queue[$this->iterated][0];
67
    }
68
69
    /**
70
     * Checks if current position is valid
71
     *
72
     * @return bool
73
     */
74 6
    public function valid(): bool
75
    {
76 6
        return $this->total > $this->iterated;
77
    }
78
79
    /**
80
     * Rewind the Iterator to the first element
81
     *
82
     * @return void
83
     */
84 2
    public function rewind(): void
85
    {
86 2
        $this->iterated = 0;
87 2
    }
88
}
89