AbstractDriver::getColumnNames()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 10
cc 3
nc 2
nop 1
crap 3
1
<?php namespace AgelxNash\Modx\Evo\Database\Drivers;
2
3
use AgelxNash\Modx\Evo\Database\Interfaces\DriverInterface;
4
use AgelxNash\Modx\Evo\Database\Traits\ConfigTrait;
5
6
abstract class AbstractDriver implements DriverInterface
7
{
8
    use ConfigTrait;
9
10
    /**
11
     * @var mixed
12
     */
13
    protected $conn;
14
15
    /**
16
     * {@inheritDoc}
17
     */
18
    abstract public function __construct(array $config = []);
19
20
    /**
21
     * {@inheritDoc}
22
     */
23
    abstract public function getConnect();
24
25
    /**
26
     * {@inheritDoc}
27
     */
28
    abstract public function isConnected();
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    abstract public function getLastError();
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    abstract public function getLastErrorNo();
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    abstract public function connect();
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    abstract public function disconnect();
49
50
    /**
51
     * {@inheritDoc}
52
     */
53
    abstract public function isResult($result);
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    abstract public function numFields($result);
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    abstract public function fieldName($result, $col = 0);
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    abstract public function setCharset($charset, $method = null);
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    abstract public function selectDb($name);
74
75
    /**
76
     * {@inheritDoc}
77
     */
78
    abstract public function escape($data);
79
80
    /**
81
     * {@inheritDoc}
82
     */
83
    abstract public function query($sql);
84
85
    /**
86
     * {@inheritDoc}
87
     */
88
    abstract public function getRecordCount($result);
89
90
    /**
91
     * {@inheritDoc}
92
     */
93
    abstract public function getRow($result, $mode = 'assoc');
94
95
    /**
96
     * {@inheritDoc}
97
     */
98
    abstract public function getVersion();
99
100
    /**
101
     * {@inheritDoc}
102
     */
103
    abstract public function getInsertId();
104
105
    /**
106
     * {@inheritDoc}
107
     */
108
    abstract public function begin($flag = 0, $name = null);
109
110
    /**
111
     * {@inheritDoc}
112
     */
113
    abstract public function commit($flag = 0, $name = null);
114
115
    /**
116
     * {@inheritDoc}
117
     */
118
    abstract public function rollback($flag = 0, $name = null);
119
120
    /**
121
     * {@inheritDoc}
122
     */
123
    abstract public function getAffectedRows();
124
125
    /**
126
     * {@inheritDoc}
127
     */
128 6
    public function getColumn($name, $result)
129
    {
130 6
        $col = [];
131
132 6
        if ($this->isResult($result)) {
133 6
            while ($row = $this->getRow($result)) {
134 6
                if (array_key_exists($name, $row)) {
135 6
                    $col[] = $row[$name];
136
                }
137
            }
138
        }
139
140 6
        return $col;
141
    }
142
143
    /**
144
     * {@inheritDoc}
145
     */
146 2
    public function getColumnNames($result)
147
    {
148 2
        $names = [];
149
150 2
        if ($this->isResult($result)) {
151 2
            $limit = $this->numFields($result);
152 2
            for ($i = 0; $i < $limit; $i++) {
153 2
                $names[] = $this->fieldName($result, $i);
154
            }
155
        }
156
157 2
        return $names;
158
    }
159
160
    /**
161
     * {@inheritDoc}
162
     */
163 14
    public function getValue($result)
164
    {
165 14
        $out = false;
166
167 14
        if ($this->isResult($result)) {
168 14
            $result = $this->getRow($result, 'num');
169 14
            $out = is_array($result) && array_key_exists(0, $result) ? $result[0] : false;
170
        }
171
172 14
        return $out;
173
    }
174
175
    /**
176
     * {@inheritDoc}
177
     */
178 2
    public function getTableMetaData($result)
179
    {
180 2
        $out = [];
181
182 2
        if ($this->isResult($result)) {
183 2
            while ($row = $this->getRow($result)) {
184 2
                $fieldName = $row['Field'];
185 2
                $out[$fieldName] = $row;
186
            }
187
        }
188
189 2
        return $out;
190
    }
191
}
192