Result   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 103
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 0

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getStatement() 0 4 1
A toArray() 0 4 1
A count() 0 4 1
A column() 0 6 1
A fetch() 0 7 2
A fetchObject() 0 6 1
A fetchAll() 0 4 1
A free() 0 4 1
A getColumnMeta() 0 4 1
A getColumnCount() 0 4 1
A getConnection() 0 4 1
A getLastFetch() 0 4 1
1
<?php
2
3
namespace Mattbit\MysqlCompat;
4
5
use PDO;
6
use PDOStatement;
7
8
class Result
9
{
10
    /**
11
     * @var Connection
12
     */
13
    protected $connection;
14
15
    /**
16
     * @var PDOStatement
17
     */
18
    protected $statement;
19
20
    /**
21
     * The last fetched row.
22
     *
23
     * @var mixed
24
     */
25
    protected $lastFetch;
26
27
    /**
28
     * Create a Result instance.
29
     *
30
     * @param PDOStatement $statement
31
     * @param Connection   $connection
32
     */
33
    public function __construct(PDOStatement $statement, Connection $connection)
34
    {
35
        $this->statement = $statement;
36
        $this->connection = $connection;
37
    }
38
39
    /**
40
     * Get the PDO statement.
41
     *
42
     * @return PDOStatement
43
     */
44
    public function getStatement()
45
    {
46
        return $this->statement;
47
    }
48
49
    public function toArray()
50
    {
51
        return $this->statement->fetchAll();
52
    }
53
54
    public function count()
55
    {
56
        return $this->statement->rowCount();
57
    }
58
59
    public function column($column, $row)
60
    {
61
        $rows = $this->statement->fetchAll(PDO::FETCH_BOTH);
62
63
        return $rows[$row][$column];
64
    }
65
66
    public function fetch($fetchMode = PDO::FETCH_BOTH, $orientation = PDO::FETCH_ORI_NEXT, $offset = 0)
67
    {
68
        $result = $this->statement->fetch($fetchMode, $orientation, $offset);
69
        $this->lastFetch = is_object($result) ? clone $result : $result;
70
71
        return $result;
72
    }
73
74
    public function fetchObject($class = 'stdClass', array $params = [])
75
    {
76
        $this->statement->setFetchMode(PDO::FETCH_CLASS, $class, $params);
77
78
        return $this->fetch(PDO::FETCH_CLASS);
79
    }
80
81
    public function fetchAll()
82
    {
83
        return $this->statement->fetchAll();
84
    }
85
86
    public function free()
87
    {
88
        return $this->statement->closeCursor();
89
    }
90
    
91
    public function getColumnMeta($columnNumber)
92
    {
93
        return $this->statement->getColumnMeta($columnNumber);
94
    }
95
96
    public function getColumnCount()
97
    {
98
        return $this->statement->columnCount();
99
    }
100
101
    public function getConnection()
102
    {
103
        return $this->connection;
104
    }
105
106
    public function getLastFetch()
107
    {
108
        return $this->lastFetch;
109
    }
110
}
111