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

AbstractIterator::rewind()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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