Completed
Push — master ( bd6b93...2911b9 )
by Rougin
02:46
created

Describe::get_primary_key()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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 18
    public function __construct(DriverInterface $driver)
31
    {
32 18
        $this->driver = $driver;
33 18
    }
34
35
    /**
36
     * Gets the primary key in the specified table.
37
     * 
38
     * @param  string $table
39
     * @return string
40
     */
41 6
    public function getPrimaryKey($table)
42
    {
43 6
        $result = '';
44
45 6
        if (empty($this->columns)) {
46 6
            $this->columns = $this->driver->getTable($table);
47 6
        }
48
49 6
        foreach ($this->columns as $column) {
50 6
            if ($column->isPrimaryKey()) {
51 6
                $result = $column->get_field();
52 6
            }
53 6
        }
54
55 6
        return $result;
56
    }
57
58
    /**
59
     * Returns the result.
60
     *
61
     * @param  string $table
62
     * @return array
63
     */
64 6
    public function getTable($table)
65
    {
66 6
        return $this->driver->getTable($table);
67
    }
68
69
    /**
70
     * Returns the result.
71
     * 
72
     * @param  string $table
73
     * @return array
74
     */
75 6
    public function get_table($table)
76
    {
77 6
        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 6
    public function get_primary_key($table)
87
    {
88 6
        return $this->getPrimaryKey($table);
89
    }
90
91
    /**
92
     * Shows the list of tables.
93
     * 
94
     * @return array
95
     */
96 6
    public function showTables()
97
    {
98 6
        return $this->driver->showTables();
99
    }
100
101
    /**
102
     * Shows the list of tables.
103
     * 
104
     * @return array
105
     */
106 6
    public function show_tables()
107
    {
108 6
        return $this->driver->showTables();
109
    }
110
}
111