Completed
Pull Request — master (#17)
by
unknown
01:37
created

AbstractExtractor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 45
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 11 2
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A rewind() 0 4 1
A valid() 0 4 1
1
<?php
2
3
namespace Extraload\Extractor\Doctrine;
4
5
use Extraload\Extractor\ExtractorInterface;
6
7
abstract class AbstractExtractor implements ExtractorInterface
8
{
9
    protected $stmt;
10
11
    protected $position;
12
13
    protected $data;
14
15
    public function extract()
16
    {
17
        if (count($this->data) >= $this->stmt->rowCount()) {
18
            return;
19
        }
20
        $this->data[$this->position] = $this->stmt->fetch();
21
        $data = $this->current();
22
        $this->next();
23
24
        return $data;
25
    }
26
27
    public function current()
28
    {
29
        return $this->data[$this->position];
30
    }
31
32
    public function key()
33
    {
34
        return $this->position;
35
    }
36
37
    public function next()
38
    {
39
        $this->position += 1;
40
    }
41
42
    public function rewind()
43
    {
44
        $this->position = 0;
45
    }
46
47
    public function valid()
48
    {
49
        return isset($this->data[$this->position]);
50
    }
51
}
52