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

GenericIterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
eloc 8
dl 0
loc 51
ccs 10
cts 10
cp 1
rs 10
c 1
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 3 1
A valid() 0 3 1
A toArray() 0 10 2
A next() 0 2 1
A rewind() 0 2 1
1
<?php
2
3
namespace ByJG\AnyDataset\Core;
4
5
use ByJG\Serializer\DumpToArrayInterface;
6
use Iterator;
7
8
abstract class GenericIterator implements IteratorInterface, Iterator, DumpToArrayInterface
9
{
10
11
    abstract public function hasNext();
12
13
    abstract public function moveNext();
14
15
    abstract public function count();
16
17
    abstract public function key();
18
19
    /**
20
     * @return array
21
     * @throws \ByJG\Serializer\Exception\InvalidArgumentException
22
     */
23 13
    public function toArray()
24
    {
25 13
        $retArray = [];
26
27 13
        while ($this->hasNext()) {
28 13
            $singleRow = $this->moveNext();
29 13
            $retArray[] = $singleRow->toArray();
30
        }
31
32 13
        return $retArray;
33
    }
34
    /* ------------------------------------- */
35
    /* PHP 5 Specific functions for Iterator */
36
    /* ------------------------------------- */
37
38
    /**
39
     * @return Row
40
     */
41 2
    public function current()
42
    {
43 2
        return $this->moveNext();
44
    }
45
46
    public function rewind()
47
    {
48
        // There is no necessary
49
    }
50
51
    public function next()
52
    {
53
        // There is no necessary
54
    }
55
56 2
    public function valid()
57
    {
58 2
        return $this->hasNext();
59
    }
60
}
61