Completed
Push — master ( a45e07...0294bf )
by Agel_Nash
02:52
created

AbstractDriver::getTableMetaData()   A

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 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
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 connect();
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    abstract public function disconnect();
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    abstract public function isConnected();
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    abstract public function escape($data);
44
45
    /**
46
     * {@inheritDoc}
47
     */
48
    abstract public function getInsertId();
49
50
    /**
51
     * {@inheritDoc}
52
     */
53
    abstract public function getAffectedRows();
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    abstract public function getVersion();
59
60
    /**
61
     * {@inheritDoc}
62
     */
63
    abstract public function getRecordCount($result);
64
65
    /**
66
     * {@inheritDoc}
67
     */
68
    abstract public function setCharset($charset, $collation, $method = null);
69
70
    /**
71
     * {@inheritDoc}
72
     */
73
    abstract public function isResult($result);
74
75
    /**
76
     * {@inheritDoc}
77
     */
78
    abstract public function numFields($result);
79
80
    /**
81
     * {@inheritDoc}
82
     */
83
    abstract public function fieldName($result, $col = 0);
84
85
    /**
86
     * {@inheritDoc}
87
     */
88
    abstract public function selectDb($name);
89
90
    /**
91
     * {@inheritDoc}
92
     */
93
    abstract public function getRow($result, $mode = 'assoc');
94
95
    /**
96
     * {@inheritDoc}
97
     */
98
    abstract public function query($query);
99
100
    /**
101
     * {@inheritDoc}
102
     */
103
    abstract public function getLastError();
104
105
    /**
106
     * {@inheritDoc}
107
     */
108
    abstract public function getLastErrorNo();
109
110
    /**
111
     * {@inheritDoc}
112
     */
113 6
    public function getColumn($name, $result)
114
    {
115 6
        $col = [];
116
117 6
        if ($this->isResult($result)) {
118 6
            while ($row = $this->getRow($result)) {
119 6
                if (array_key_exists($name, $row)) {
120 6
                    $col[] = $row[$name];
121
                }
122
            }
123
        }
124
125 6
        return $col;
126
    }
127
128
    /**
129
     * {@inheritDoc}
130
     */
131 2
    public function getColumnNames($result)
132
    {
133 2
        $names = [];
134
135 2
        if ($this->isResult($result)) {
136 2
            $limit = $this->numFields($result);
137 2
            for ($i = 0; $i < $limit; $i++) {
138 2
                $names[] = $this->fieldName($result, $i);
139
            }
140
        }
141
142 2
        return $names;
143
    }
144
145
    /**
146
     * {@inheritDoc}
147
     */
148 6
    public function getValue($result)
149
    {
150 6
        $out = false;
151
152 6
        if ($this->isResult($result)) {
153 6
            $result = $this->getRow($result, 'num');
154 6
            $out = isset($result[0]) ? $result[0] : false;
155
        }
156
157 6
        return $out;
158
    }
159
160
    /**
161
     * {@inheritDoc}
162
     */
163 2
    public function getTableMetaData($result)
164
    {
165 2
        $out = [];
166
167 2
        if ($this->isResult($result)) {
168 2
            while ($row = $this->getRow($result)) {
169 2
                $fieldName = $row['Field'];
170 2
                $out[$fieldName] = $row;
171
            }
172
        }
173
174 2
        return $out;
175
    }
176
}
177