ListHydrator25::hydrateAllData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Vivait\BootstrapBundle\Hydrator;
4
5
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
6
use PDO;
7
8
/**
9
 * Compatible with Doctrine ORM 2.5
10
 */
11 View Code Duplication
class ListHydrator25 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...
12
{
13
    protected function hydrateAllData()
14
    {
15
        $result = $cache = array();
0 ignored issues
show
Unused Code introduced by
$cache is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
16
17
        foreach ($this->_stmt->fetchAll(PDO::FETCH_ASSOC) as $row) {
18
            $this->hydrateRowData($row, $result);
19
        }
20
21
        return $result;
22
    }
23
24
    protected function hydrateRowData(array $data, array &$result)
25
    {
26
        if (count($data) == 0) {
27
            return false;
28
        }
29
30
        $keys = array_keys($data);
31
32
        // Assume first column is id field
33
        $id = $data[$keys[0]];
34
35
        if (count($data) == 2) {
36
            // If only one more field assume that this is the value field
37
            $value = $data[$keys[1]];
38
        } else {
39
            // Remove ID field and add remaining fields as value array
40
            array_shift($data);
41
            $value = $data;
42
        }
43
44
        $result[$id] = $value;
45
    }
46
}