Completed
Pull Request — master (#2)
by Joao
05:22
created

GenericIterator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

9 Methods

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