Passed
Pull Request — master (#10)
by Joao
01:36
created

AnyIterator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 12
dl 0
loc 69
ccs 12
cts 15
cp 0.8
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A key() 0 3 1
A __construct() 0 4 1
A hasNext() 0 3 1
A moveNext() 0 6 2
A withFilter() 0 3 1
A count() 0 3 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 17
    public function __construct($list)
29
    {
30 17
        $this->curRow = 0;
31 17
        $this->list = $list;
32
    }
33
34
    /**
35
     * How many elements have
36
     * @return int
37
     */
38 17
    public function count()
39
    {
40 17
        return count($this->list);
41
    }
42
43
    /**
44
     * Ask the Iterator is exists more rows. Use before moveNext method.
45
     * @return bool True if exist more rows, otherwise false
46
     */
47 16
    public function hasNext()
48
    {
49 16
        return ($this->curRow < $this->count());
50
    }
51
52
    /**
53
     * Return the next row.
54
     *
55
     * @return Row|null
56
     */
57 16
    public function moveNext()
58
    {
59 16
        if (!$this->hasNext()) {
60
            return null;
61
        }
62 16
        return $this->list[$this->curRow++];
63
    }
64
65
    public function key()
66
    {
67
        return $this->curRow;
68
    }
69
70
    /**
71
     * @param IteratorFilter $filter
72
     * @return AnyIterator
73
     */
74 1
    public function withFilter(IteratorFilter $filter)
75
    {
76 1
        return new AnyIterator($filter->match($this->list));
77
    }
78
}
79