AnyIterator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A key() 0 3 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 18
    public function __construct($list)
29
    {
30 18
        $this->curRow = 0;
31 18
        $this->list = $list;
32
    }
33
34
    /**
35
     * @inheritDoc
36
     */
37 18
    public function count()
38
    {
39 18
        return count($this->list);
40
    }
41
42
    /**
43
     * @inheritDoc
44
     */
45 17
    public function hasNext()
46
    {
47 17
        return ($this->curRow < $this->count());
48
    }
49
50
    /**
51
     * @inheritDoc
52
     */
53 17
    public function moveNext()
54
    {
55 17
        if (!$this->hasNext()) {
56
            return null;
57
        }
58 17
        return $this->list[$this->curRow++];
59
    }
60
61
    /**
62
     * @inheritDoc
63
     */
64
    public function key()
65
    {
66
        return $this->curRow;
67
    }
68
69
    /**
70
     * @param IteratorFilter $filter
71
     * @return AnyIterator
72
     */
73 1
    public function withFilter(IteratorFilter $filter)
74
    {
75 1
        return new AnyIterator($filter->match($this->list));
76
    }
77
}
78