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

Result   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __destruct() 0 4 1
A affected() 0 4 1
A insertID() 0 4 1
A toArray() 0 4 1
A count() 0 4 1
A key() 0 4 1
A current() 0 4 1
A rewind() 0 9 2
A next() 0 5 1
A valid() 0 4 1
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
}