Completed
Push — master ( 35c3f5...647ae2 )
by Rougin
02:51
created

Describe::getColumns()   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 0
Metric Value
c 0
b 0
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 Doctrine\Common\Inflector\Inflector;
6
7
/**
8
 * Describe
9
 *
10
 * Gets information of a table schema from a database.
11
 * NOTE: To be removed in v2.0.0. Use Table class instead.
12
 *
13
 * @package Describe
14
 * @author  Rougin Royce Gutib <[email protected]>
15
 */
16
class Describe
17
{
18
    /**
19
     * @var \Rougin\Describe\Driver\DriverInterface
20
     */
21
    protected $driver;
22
23
    /**
24
     * @param \Rougin\Describe\Driver\DriverInterface $driver
25
     */
26 159
    public function __construct(Driver\DriverInterface $driver)
27
    {
28 159
        $this->driver = $driver;
29 159
    }
30
31
    /**
32
     * Returns an array of Column instances from a table.
33
     *
34
     * @param  string $table
35
     * @return \Rougin\Describe\Column[]
36
     */
37 24
    public function columns($table)
38
    {
39 24
        return $this->driver->columns($table);
40
    }
41
42
    /**
43
     * Returns an array of Column instances from a table.
44
     * NOTE: To be removed in v2.0.0. Use columns() instead.
45
     *
46
     * @param  string $table
47
     * @return \Rougin\Describe\Column[]
48
     */
49 24
    public function getColumns($table)
50
    {
51 24
        return $this->driver->getColumns($table);
52
    }
53
54
    /**
55
     * Returns the primary key of a table.
56
     * NOTE: To be removed in v2.0.0. Use primary() instead.
57
     *
58
     * @param  string  $table
59
     * @param  boolean $object
60
     * @return \Rougin\Describe\Column|string
61
     */
62 12
    public function getPrimaryKey($table, $object = false)
63
    {
64 12
        return $this->primary($table, $object);
65
    }
66
67
    /**
68
     * Returns an array of columns from a table.
69
     * NOTE: To be removed in v2.0.0. Use getColumns() instead.
70
     *
71
     * @param  string $table
72
     * @return array
73
     */
74 51
    public function getTable($table)
75
    {
76 51
        return $this->driver->getTable($table);
77
    }
78
79
    /**
80
     * Returns an array of table names.
81
     * NOTE: To be removed in v2.0.0. Use tables() instead.
82
     *
83
     * @return array
84
     */
85 12
    public function getTableNames()
86
    {
87 12
        return $this->driver->getTableNames();
88
    }
89
90
    /**
91
     * Returns the primary key of a table.
92
     *
93
     * @param  string  $table
94
     * @param  boolean $object
95
     * @return \Rougin\Describe\Column|string
96
     */
97 24
    public function primary($table, $object = false)
98
    {
99 24
        $table = new Table($table, $this->driver);
100
101 24
        ($result = $table->primary()) === null && $result = '';
102
103 24
        return $object ? $result : $result->getField();
104
    }
105
106
    /**
107
     * Returns an array of table names.
108
     * NOTE: To be removed in v2.0.0. Use getTableNames() instead.
109
     *
110
     * @return array
111
     */
112 12
    public function showTables()
113
    {
114 12
        return $this->driver->showTables();
115
    }
116
117
    /**
118
     * Returns an array of Table instances.
119
     *
120
     * @return \Rougin\Describe\Table[]
121
     */
122 12
    public function tables()
123
    {
124 12
        return $this->driver->tables();
125
    }
126
127
    /**
128
     * Calls methods from this class in underscore case.
129
     * NOTE: To be removed in v2.0.0. All new methods are now in one word.
130
     *
131
     * @param  string $method
132
     * @param  mixed  $parameters
133
     * @return mixed
134
     */
135 12
    public function __call($method, $parameters)
136
    {
137 12
        $method = Inflector::camelize($method);
138
139 12
        $instance = array($this, $method);
140
141 12
        return call_user_func_array($instance, $parameters);
142
    }
143
}
144