Completed
Push — master ( 411617...e3a891 )
by Joao
06:19 queued 04:00
created

AnyIterator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace ByJG\AnyDataset\Core;
4
5
/**
6
 * Iterator class is a structure used to navigate forward in a AnyDataset structure.
7
 */
8
class AnyIterator extends GenericIterator
9
{
10
11
    /**
12
     * Row Elements
13
     * @var array
14
     */
15
    private $list;
16
17
    /**
18
     * Current row number
19
     * @var int
20
     */
21
    private $curRow; //int
22
23
    /**
24
     * Iterator constructor
25
     *
26
*@param Row[] $list
27
     */
28
29 13
    public function __construct($list)
30
    {
31 13
        $this->curRow = 0;
32 13
        $this->list = $list;
33 13
    }
34
35
    /**
36
     * How many elements have
37
     * @return int
38
     */
39 13
    public function count()
40
    {
41 13
        return count($this->list);
42
    }
43
44
    /**
45
     * Ask the Iterator is exists more rows. Use before moveNext method.
46
     * @return bool True if exist more rows, otherwise false
47
     */
48 12
    public function hasNext()
49
    {
50 12
        return ($this->curRow < $this->count());
51
    }
52
53
    /**
54
     * Return the next row.
55
     *
56
*@return Row
57
     */
58 12
    public function moveNext()
59
    {
60 12
        if (!$this->hasNext()) {
61
            return null;
62
        }
63 12
        return $this->list[$this->curRow++];
64
    }
65
66
    public function key()
67
    {
68
        return $this->curRow;
69
    }
70
}
71