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

GenericIterator::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 0
crap 2
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