Completed
Pull Request — master (#5)
by Rougin
02:15
created

AbstractDriver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 43
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getColumnsFromQuery() 0 19 3
setColumn() 0 1 ?
1
<?php
2
3
namespace Rougin\Describe\Driver;
4
5
/**
6
 * Abstract Driver
7
 *
8
 * @package  Describe
9
 * @category Driver
10
 * @author   Rougin Royce Gutib <[email protected]>
11
 */
12
abstract class AbstractDriver
13
{
14
    /**
15
     * @var \PDO
16
     */
17
    protected $pdo;
18
19
    /**
20
     * Returns the list of columns based on the specified query.
21
     *
22
     * @param  string $tableName
23
     * @param  string $query
24
     * @return void
25
     */
26 69
    public function getColumnsFromQuery($tableName, $query)
27
    {
28 69
        $columns = [];
29
30
        try {
31 69
            $information = $this->pdo->prepare($query);
32
33 69
            $information->execute();
34 69
            $information->setFetchMode(\PDO::FETCH_OBJ);
35 69
        } catch (\PDOException $e) {
36
            // Table not found
37
        }
38
39 69
        while ($row = $information->fetch()) {
40 63
            array_push($columns, $this->setColumn($tableName, $row));
41 63
        }
42
43 69
        return $columns;
44
    }
45
46
    /**
47
     * Prepares the defined columns.
48
     *
49
     * @param  string $tableName
50
     * @param  mixed  $row
51
     * @return \Rougin\Describe\Column
52
     */
53
    abstract protected function setColumn($tableName, $row);
54
}
55