Completed
Push — master ( b71ad6...2211ef )
by Ivan
08:51
created

Result::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace vakata\database\driver\postgre;
4
5
use \vakata\database\DBException;
6
use \vakata\database\DriverInterface;
7
use \vakata\database\ResultInterface;
8
use \vakata\collection\Collection;
9
10
class Result implements ResultInterface
11
{
12
    protected $statement;
13
    protected $last = null;
14
    protected $fetched = -1;
15
    protected $iid = null;
16
    protected $aff = 0;
17
18
    public function __construct($statement, $iid, $aff)
19
    {
20
        $this->statement = $statement;
21
        $this->iid = $iid;
22
        $this->aff = $aff;
23
    }
24
    public function __destruct()
25
    {
26
        @\pg_free_result($this->statement);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
27
    }
28
    public function affected() : int
29
    {
30
        return $this->aff;
31
    }
32
    public function insertID()
33
    {
34
        return $this->iid;
35
    }
36
    public function toArray() : array
37
    {
38
        return iterator_to_array($this);
39
    }
40
41
    public function count()
42
    {
43
        return \pg_num_rows($this->statement);
44
    }
45
46
    public function key()
47
    {
48
        return $this->fetched;
49
    }
50
    public function current()
51
    {
52
        return $this->last;
53
    }
54
    public function rewind()
55
    {
56
        if ($this->fetched >= 0) {
57
            \pg_result_seek($this->statement, 0);
58
        }
59
        $this->last = null;
60
        $this->fetched = -1;
61
        $this->next();
62
    }
63
    public function next()
64
    {
65
        $this->fetched ++;
66
        $this->last = \pg_fetch_array($this->statement, null, \PGSQL_ASSOC);
67
    }
68
    public function valid()
69
    {
70
        return !!$this->last;
71
    }
72
}