Completed
Pull Request — master (#17)
by
unknown
10:00
created

QueryExtractor   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A extract() 0 7 1
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 Doctrine\DBAL\Connection;
6
use Extraload\Extractor\ExtractorInterface;
7
8
class QueryExtractor implements ExtractorInterface
9
{
10
    private $position = 0;
11
12
    private $data;
13
14
    public function __construct(Connection $conn, string $sql)
15
    {
16
        $this->position = 0;
17
        $this->data = $conn->query($sql)->fetchAll();
18
    }
19
20
    public function extract()
21
    {
22
        $data = $this->current();
23
        $this->next();
24
25
        return $data;
26
    }
27
28
    public function current()
29
    {
30
        return $this->data[$this->position];
31
    }
32
33
    public function key()
34
    {
35
        return $this->position;
36
    }
37
38
    public function next()
39
    {
40
        $this->position += 1;
41
    }
42
43
    public function rewind()
44
    {
45
        $this->position = 0;
46
    }
47
48
    public function valid()
49
    {
50
        return isset($this->data[$this->position]);
51
    }
52
}
53