Completed
Pull Request — master (#1)
by Rougin
07:32
created

Describe::get_table()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Rougin\Describe;
4
5
use Rougin\Describe\Driver\DriverInterface;
6
7
/**
8
 * Describe
9
 *
10
 * Gets information of a table schema from a database.
11
 *
12
 * @package Describe
13
 * @author  Rougin Royce Gutib <[email protected]>
14
 */
15
class Describe
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $columns = [];
21
22
    /**
23
     * @var \Rougin\Describe\Driver\DriverInterface
24
     */
25
    protected $driver;
26
27
    /**
28
     * @param \Rougin\Describe\Driver\DriverInterface $driver
29
     */
30 27
    public function __construct(DriverInterface $driver)
31
    {
32 27
        $this->driver = $driver;
33 27
    }
34
35
    /**
36
     * Gets the primary key in the specified table.
37
     *
38
     * @param  string $table
39
     * @return string
40
     */
41 9
    public function getPrimaryKey($table)
42
    {
43 9
        $result = '';
44
45 9
        if (empty($this->columns)) {
46 9
            $this->columns = $this->driver->getTable($table);
47
        }
48
49
        foreach ($this->columns as $column) {
50
            if ($column->isPrimaryKey()) {
51
                $result = $column->get_field();
52
            }
53
        }
54
55
        return $result;
56
    }
57
58
    /**
59
     * Returns the result.
60
     *
61
     * @param  string $table
62
     * @return array
63
     */
64 9
    public function getTable($table)
65
    {
66 9
        return $this->driver->getTable($table);
67
    }
68
69
    /**
70
     * Returns the result.
71
     *
72
     * @param  string $table
73
     * @return array
74
     */
75
    public function get_table($table)
76
    {
77
        return $this->driver->getTable($table);
78
    }
79
80
    /**
81
     * Gets the primary key in the specified table.
82
     *
83
     * @param  string $table
84
     * @return string
85
     */
86
    public function get_primary_key($table)
87
    {
88
        return $this->getPrimaryKey($table);
89
    }
90
91
    /**
92
     * Shows the list of tables.
93
     *
94
     * @return array
95
     */
96 9
    public function showTables()
97
    {
98 9
        return $this->driver->showTables();
99
    }
100
101
    /**
102
     * Shows the list of tables.
103
     *
104
     * @return array
105
     */
106 3
    public function show_tables()
107
    {
108 3
        return $this->driver->showTables();
109
    }
110
}
111