ResultSetAdapter   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 133
rs 10
wmc 17

12 Methods

Rating   Name   Duplication   Size   Complexity  
A fetchAll() 0 13 3
A fetch() 0 14 3
A getNumRows() 0 3 1
A rewind() 0 2 1
A toRow() 0 3 1
A valid() 0 3 1
A isDml() 0 3 1
A getAffectedRows() 0 3 1
A getFields() 0 9 2
A freeResult() 0 3 1
A store() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace Foolz\SphinxQL\Drivers\Pdo;
4
5
use Foolz\SphinxQL\Drivers\ResultSetAdapterInterface;
6
use PDO;
7
use PDOStatement;
8
9
class ResultSetAdapter implements ResultSetAdapterInterface
10
{
11
    /**
12
     * @var PDOStatement
13
     */
14
    protected $statement;
15
16
    /**
17
     * @var bool
18
     */
19
    protected $valid = true;
20
21
    /**
22
     * @param PDOStatement $statement
23
     */
24
    public function __construct(PDOStatement $statement)
25
    {
26
        $this->statement = $statement;
27
    }
28
29
    /**
30
     * @inheritdoc
31
     */
32
    public function getAffectedRows()
33
    {
34
        return $this->statement->rowCount();
35
    }
36
37
    /**
38
     * @inheritdoc
39
     */
40
    public function getNumRows()
41
    {
42
        return $this->statement->rowCount();
43
    }
44
45
    /**
46
     * @inheritdoc
47
     */
48
    public function getFields()
49
    {
50
        $fields = array();
51
52
        for ($i = 0; $i < $this->statement->columnCount(); $i++) {
53
            $fields[] = (object)$this->statement->getColumnMeta($i);
54
        }
55
56
        return $fields;
57
    }
58
59
    /**
60
     * @inheritdoc
61
     */
62
    public function isDml()
63
    {
64
        return $this->statement->columnCount() == 0;
65
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70
    public function store()
71
    {
72
        return $this->statement->fetchAll(PDO::FETCH_NUM);
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78
    public function toRow($num)
79
    {
80
        throw new \BadMethodCallException('Not implemented');
81
    }
82
83
    /**
84
     * @inheritdoc
85
     */
86
    public function freeResult()
87
    {
88
        $this->statement->closeCursor();
89
    }
90
91
    /**
92
     * @inheritdoc
93
     */
94
    public function rewind()
95
    {
96
97
    }
98
99
    /**
100
     * @inheritdoc
101
     */
102
    public function valid()
103
    {
104
        return $this->valid;
105
    }
106
107
    /**
108
     * @inheritdoc
109
     */
110
    public function fetch($assoc = true)
111
    {
112
        if ($assoc) {
113
            $row = $this->statement->fetch(PDO::FETCH_ASSOC);
114
        } else {
115
            $row = $this->statement->fetch(PDO::FETCH_NUM);
116
        }
117
118
        if (!$row) {
119
            $this->valid = false;
120
            $row = null;
121
        }
122
123
        return $row;
124
    }
125
126
    /**
127
     * @inheritdoc
128
     */
129
    public function fetchAll($assoc = true)
130
    {
131
        if ($assoc) {
132
            $row = $this->statement->fetchAll(PDO::FETCH_ASSOC);
133
        } else {
134
            $row = $this->statement->fetchAll(PDO::FETCH_NUM);
135
        }
136
137
        if (empty($row)) {
138
            $this->valid = false;
139
        }
140
141
        return $row;
142
    }
143
}
144