ListHydrator::hydrateRowData()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.568
c 0
b 0
f 0
cc 3
nc 3
nop 3
1
<?php
2
3
namespace Vivait\BootstrapBundle\Hydrator;
4
5
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
6
use PDO;
7
8 View Code Duplication
class ListHydrator extends AbstractHydrator
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    protected function hydrateAllData()
11
    {
12
        $result = $cache = array();
13
14
        foreach ($this->_stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
15
            $this->hydrateRowData($row, $cache, $result);
16
        }
17
18
        return $result;
19
    }
20
21
    protected function hydrateRowData(array $data, array &$cache, array &$result)
22
    {
23
        if (count($data) == 0) {
24
            return false;
25
        }
26
27
        $keys = array_keys($data);
28
29
        // Assume first column is id field
30
        $id = $data[$keys[0]];
31
32
        if (count($data) == 2) {
33
            // If only one more field assume that this is the value field
34
            $value = $data[$keys[1]];
35
        } else {
36
            // Remove ID field and add remaining fields as value array
37
            array_shift($data);
38
            $value = $data;
39
        }
40
41
        $result[$id] = $value;
42
    }
43
}