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

AnyIterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 63
ccs 11
cts 14
cp 0.7856
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A count() 0 4 1
A hasNext() 0 4 1
A moveNext() 0 7 2
A key() 0 4 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