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

QueryExtractor   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 24 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 12
loc 50
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 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
A extract() 12 12 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 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...
21
    {
22
        if ($this->position >= count($this->data)) {
23
            return;
24
        }
25
26
        $data = $this->current();
27
28
        $this->next();
29
30
        return $data;
31
    }
32
33
    public function current()
34
    {
35
        return $this->data[$this->position];
36
    }
37
38
    public function key()
39
    {
40
        return $this->position;
41
    }
42
43
    public function next()
44
    {
45
        $this->position += 1;
46
    }
47
48
    public function rewind()
49
    {
50
        $this->position = 0;
51
    }
52
53
    public function valid()
54
    {
55
        return isset($this->data[$this->position]);
56
    }
57
}
58