Passed
Push — main ( 08bfff...5ea9ef )
by Thierry
01:30
created

TableTrait::alterTable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 9
dl 0
loc 5
rs 10
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Lagdo\DbAdmin\Driver;
4
5
use Lagdo\DbAdmin\Driver\Entity\ConfigEntity;
6
use Lagdo\DbAdmin\Driver\Entity\TableEntity;
7
use Lagdo\DbAdmin\Driver\Entity\ForeignKeyEntity;
8
use Lagdo\DbAdmin\Driver\Entity\TriggerEntity;
9
use Lagdo\DbAdmin\Driver\Entity\RoutineEntity;
10
11
use Lagdo\DbAdmin\Driver\Db\ConnectionInterface;
12
13
trait TableTrait
14
{
15
    /**
16
     * Get the name of the primary id field
17
     *
18
     * @return string
19
     */
20
    public function primaryIdName()
21
    {
22
        return $this->table->primaryIdName();
23
    }
24
25
    /**
26
     * Get table status
27
     *
28
     * @param string $table
29
     * @param bool $fast Return only "Name", "Engine" and "Comment" fields
30
     *
31
     * @return TableEntity|null
32
     */
33
    public function tableStatus(string $table, bool $fast = false)
34
    {
35
        return $this->table->tableStatus($table, $fast);
36
    }
37
38
    /**
39
     * Get all tables statuses
40
     *
41
     * @param bool $fast Return only "Name", "Engine" and "Comment" fields
42
     *
43
     * @return TableEntity[]
44
     */
45
    public function tablesStatuses(bool $fast = false)
46
    {
47
        return $this->table->tablesStatuses($fast);
48
    }
49
50
    /**
51
     * Get status of a single table and fall back to name on error
52
     *
53
     * @param string $table
54
     * @param bool $fast Return only "Name", "Engine" and "Comment" fields
55
     *
56
     * @return TableEntity
57
     */
58
    public function tableStatusOrName(string $table, bool $fast = false)
59
    {
60
        return $this->table->tableStatusOrName($table, $fast);
61
    }
62
63
    /**
64
     * Find out whether the identifier is view
65
     *
66
     * @param TableEntity $tableStatus
67
     *
68
     * @return bool
69
     */
70
    public function isView(TableEntity $tableStatus)
71
    {
72
        return $this->table->isView($tableStatus);
73
    }
74
75
    /**
76
     * Check if table supports foreign keys
77
     *
78
     * @param TableEntity $tableStatus
79
     *
80
     * @return bool
81
     */
82
    public function supportForeignKeys(TableEntity $tableStatus)
83
    {
84
        return $this->table->supportForeignKeys($tableStatus);
85
    }
86
87
    /**
88
     * Get information about fields
89
     *
90
     * @param string $table
91
     *
92
     * @return array
93
     */
94
    public function fields(string $table)
95
    {
96
        return $this->table->fields($table);
97
    }
98
99
    /**
100
     * Get table indexes
101
     *
102
     * @param string $table
103
     * @param ConnectionInterface $connection
104
     *
105
     * @return array
106
     */
107
    public function indexes(string $table, ConnectionInterface $connection = null)
108
    {
109
        return $this->table->indexes($table, $connection);
110
    }
111
112
    /**
113
     * Get foreign keys in table
114
     *
115
     * @param string $table
116
     *
117
     * @return array array($name => array("db" => , "ns" => , "table" => , "source" => [], "target" => [], "onDelete" => , "onUpdate" => ))
118
     */
119
    public function foreignKeys(string $table)
120
    {
121
        return $this->table->foreignKeys($table);
122
    }
123
124
    /**
125
     * Create or alter table
126
     *
127
     * @param string $table "" to create
128
     * @param string $name new name
129
     * @param array $fields of array($orig, $process_field, $after)
130
     * @param array $foreign of strings
131
     * @param string $comment
132
     * @param string $engine
133
     * @param string $collation
134
     * @param int $autoIncrement number
135
     * @param string $partitioning
136
     *
137
     * @return bool
138
     */
139
    public function alterTable(string $table, string $name, array $fields, array $foreign,
140
        string $comment, string $engine, string $collation, int $autoIncrement, string $partitioning)
141
    {
142
        return $this->table->alterTable($table, $name, $fields, $foreign, $comment,
143
            $engine, $collation, $autoIncrement, $partitioning);
144
    }
145
146
    /**
147
     * Alter indexes
148
     *
149
     * @param string $table     Escaped table name
150
     * @param array $alter      array("index type", "name", array("column definition", ...)) or array("index type", "name", "DROP")
151
     *
152
     * @return bool
153
     */
154
    public function alterIndexes(string $table, array $alter)
155
    {
156
        return $this->table->alterIndexes($table, $alter);
157
    }
158
159
    /**
160
     * Get information about a trigger
161
     *
162
     * @param string $trigger
163
     *
164
     * @return TriggerEntity
165
     */
166
    public function trigger(string $trigger)
167
    {
168
        return $this->table->trigger($trigger);
169
    }
170
171
    /**
172
     * Get defined triggers
173
     *
174
     * @param string $table
175
     *
176
     * @return array
177
     */
178
    public function triggers(string $table)
179
    {
180
        return $this->table->triggers($table);
181
    }
182
183
    /**
184
     * Get trigger options
185
     *
186
     * @return array ("Timing" => [], "Event" => [], "Type" => [])
187
     */
188
    public function triggerOptions()
189
    {
190
        return $this->table->triggerOptions();
191
    }
192
193
    /**
194
     * Find backward keys for table
195
     *
196
     * @param string $table
197
     * @param string $tableName
198
     *
199
     * @return array
200
     */
201
    public function backwardKeys(string $table, string $tableName)
202
    {
203
        return $this->table->backwardKeys($table, $tableName);
204
    }
205
206
    /**
207
     * Get descriptions of selected data
208
     *
209
     * @param array $rows All data to print
210
     * @param array $foreignKeys
211
     *
212
     * @return array
213
     */
214
    public function rowDescriptions(array $rows, array $foreignKeys)
215
    {
216
        return $this->table->rowDescriptions($rows, $foreignKeys);
217
    }
218
219
    /**
220
     * Find out foreign keys for each column
221
     *
222
     * @param string $table
223
     *
224
     * @return array
225
     */
226
    public function columnForeignKeys(string $table)
227
    {
228
        return $this->table->columnForeignKeys($table);
229
    }
230
231
    /**
232
     * Get referencable tables with single column primary key except self
233
     *
234
     * @param string $table
235
     *
236
     * @return array
237
     */
238
    public function referencableTables(string $table)
239
    {
240
        return $this->table->referencableTables($table);
241
    }
242
243
    /**
244
     * Get help link for table
245
     *
246
     * @param string $name
247
     *
248
     * @return string relative URL or null
249
     */
250
    public function tableHelp(string $name)
251
    {
252
        return $this->table->tableHelp($name);
253
    }
254
}
255