Passed
Push — fix-6460 ( 379c3e...254990 )
by Sam
09:57
created

PDOQuery::fetchAllPgsql()   A

Complexity

Conditions 5
Paths 2

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 2
nop 1
dl 0
loc 23
rs 9.5222
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\ORM\Connect;
4
5
/**
6
 * A result-set from a PDO database.
7
 */
8
class PDOQuery extends Query
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $results = null;
14
15
    /**
16
     * Hook the result-set given into a Query class, suitable for use by SilverStripe.
17
     * @param PDOStatement $statement The internal PDOStatement containing the results
18
     */
19
    public function __construct(PDOStatementHandle $statement)
20
    {
21
        // Since no more than one PDOStatement for any one connection can be safely
22
        // traversed, each statement simply requests all rows at once for safety.
23
        // This could be re-engineered to call fetchAll on an as-needed basis
24
25
        $this->results = $statement->typeCorrectedFetchAll();
26
        $statement->closeCursor();
27
    }
28
29
    public function seek($row)
30
    {
31
        $this->rowNum = $row - 1;
32
        return $this->nextRecord();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->nextRecord() also could return the type false which is incompatible with the return type mandated by SilverStripe\ORM\Connect\Query::seek() of array.
Loading history...
33
    }
34
35
    public function numRecords()
36
    {
37
        return count($this->results);
38
    }
39
40
    public function nextRecord()
41
    {
42
        $index = $this->rowNum + 1;
43
44
        if (isset($this->results[$index])) {
45
            return $this->results[$index];
46
        } else {
47
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the return type mandated by SilverStripe\ORM\Connect\Query::nextRecord() of array.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
48
        }
49
    }
50
}
51