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

PreparedQueryExtractor::extract()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
1
<?php
2
3
namespace Extraload\Extractor\Doctrine;
4
5
use Doctrine\DBAL\Connection;
6
use Extraload\Extractor\ExtractorInterface;
7
8
class PreparedQueryExtractor implements ExtractorInterface
9
{
10
    private $position = 0;
11
12
    private $data;
13
14
    public function __construct(Connection $conn, string $sql, array $values)
15
    {
16
        $this->position = 0;
17
18
        $stmt = $conn->prepare($sql);
19
20
        foreach ($values as $value) {
21
            $stmt->bindValue(
22
                $value['parameter'],
23
                $value['value'],
24
                $value['data_type'] ?? null
25
            );
26
        }
27
28
        $stmt->execute();
29
30
        $this->data = $stmt->fetchAll();
31
    }
32
33 View Code Duplication
    public function extract()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        if ($this->position >= count($this->data)) {
36
            return;
37
        }
38
39
        $data = $this->current();
40
41
        $this->next();
42
43
        return $data;
44
    }
45
46
    public function current()
47
    {
48
        return $this->data[$this->position];
49
    }
50
51
    public function key()
52
    {
53
        return $this->position;
54
    }
55
56
    public function next()
57
    {
58
        $this->position += 1;
59
    }
60
61
    public function rewind()
62
    {
63
        $this->position = 0;
64
    }
65
66
    public function valid()
67
    {
68
        return isset($this->data[$this->position]);
69
    }
70
}
71