Total Complexity | 70 |
Total Lines | 718 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 0 |
Complex classes like Schema often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Schema, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | final class Schema extends AbstractSchema implements ConstraintFinderInterface |
||
38 | { |
||
39 | use ConstraintFinderTrait; |
||
40 | |||
41 | private bool $oldMysql; |
||
42 | private array $typeMap = [ |
||
43 | 'tinyint' => self::TYPE_TINYINT, |
||
44 | 'bit' => self::TYPE_INTEGER, |
||
45 | 'smallint' => self::TYPE_SMALLINT, |
||
46 | 'mediumint' => self::TYPE_INTEGER, |
||
47 | 'int' => self::TYPE_INTEGER, |
||
48 | 'integer' => self::TYPE_INTEGER, |
||
49 | 'bigint' => self::TYPE_BIGINT, |
||
50 | 'float' => self::TYPE_FLOAT, |
||
51 | 'double' => self::TYPE_DOUBLE, |
||
52 | 'real' => self::TYPE_FLOAT, |
||
53 | 'decimal' => self::TYPE_DECIMAL, |
||
54 | 'numeric' => self::TYPE_DECIMAL, |
||
55 | 'tinytext' => self::TYPE_TEXT, |
||
56 | 'mediumtext' => self::TYPE_TEXT, |
||
57 | 'longtext' => self::TYPE_TEXT, |
||
58 | 'longblob' => self::TYPE_BINARY, |
||
59 | 'blob' => self::TYPE_BINARY, |
||
60 | 'text' => self::TYPE_TEXT, |
||
61 | 'varchar' => self::TYPE_STRING, |
||
62 | 'string' => self::TYPE_STRING, |
||
63 | 'char' => self::TYPE_CHAR, |
||
64 | 'datetime' => self::TYPE_DATETIME, |
||
65 | 'year' => self::TYPE_DATE, |
||
66 | 'date' => self::TYPE_DATE, |
||
67 | 'time' => self::TYPE_TIME, |
||
68 | 'timestamp' => self::TYPE_TIMESTAMP, |
||
69 | 'enum' => self::TYPE_STRING, |
||
70 | 'varbinary' => self::TYPE_BINARY, |
||
71 | 'json' => self::TYPE_JSON, |
||
72 | ]; |
||
73 | |||
74 | /** |
||
75 | * @var string|string[] character used to quote schema, table, etc. names. An array of 2 characters can be used in |
||
76 | * case starting and ending characters are different. |
||
77 | */ |
||
78 | protected $tableQuoteCharacter = '`'; |
||
79 | |||
80 | /** |
||
81 | * @var string|string[] character used to quote column names. An array of 2 characters can be used in case starting |
||
82 | * and ending characters are different. |
||
83 | */ |
||
84 | protected $columnQuoteCharacter = '`'; |
||
85 | |||
86 | /** |
||
87 | * Resolves the table name and schema name (if any). |
||
88 | * |
||
89 | * @param string $name the table name. |
||
90 | * |
||
91 | * @return TableSchema |
||
92 | * |
||
93 | * {@see TableSchema} |
||
94 | */ |
||
95 | protected function resolveTableName(string $name): TableSchema |
||
96 | { |
||
97 | $resolvedName = new TableSchema(); |
||
98 | |||
99 | $parts = explode('.', str_replace('`', '', $name)); |
||
100 | |||
101 | if (isset($parts[1])) { |
||
102 | $resolvedName->schemaName($parts[0]); |
||
103 | $resolvedName->name($parts[1]); |
||
104 | } else { |
||
105 | $resolvedName->schemaName($this->defaultSchema); |
||
106 | $resolvedName->name($name); |
||
107 | } |
||
108 | |||
109 | $resolvedName->fullName(($resolvedName->getSchemaName() !== $this->defaultSchema ? |
||
110 | $resolvedName->getSchemaName() . '.' : '') . $resolvedName->getName()); |
||
111 | |||
112 | return $resolvedName; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Returns all table names in the database. |
||
117 | * |
||
118 | * This method should be overridden by child classes in order to support this feature because the default |
||
119 | * implementation simply throws an exception. |
||
120 | * |
||
121 | * @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
||
122 | * |
||
123 | * @throws Exception |
||
124 | * @throws InvalidConfigException |
||
125 | * @throws InvalidArgumentException |
||
126 | * |
||
127 | * @return array all table names in the database. The names have NO schema name prefix. |
||
128 | */ |
||
129 | protected function findTableNames(string $schema = ''): array |
||
130 | { |
||
131 | $sql = 'SHOW TABLES'; |
||
132 | |||
133 | if ($schema !== '') { |
||
134 | $sql .= ' FROM ' . $this->quoteSimpleTableName($schema); |
||
135 | } |
||
136 | |||
137 | return $this->getDb()->createCommand($sql)->queryColumn(); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Loads the metadata for the specified table. |
||
142 | * |
||
143 | * @param string $name table name. |
||
144 | * |
||
145 | * @throws Exception |
||
146 | * |
||
147 | * @return TableSchema|null DBMS-dependent table metadata, `null` if the table does not exist. |
||
148 | */ |
||
149 | protected function loadTableSchema(string $name): ?TableSchema |
||
150 | { |
||
151 | $table = new TableSchema(); |
||
152 | |||
153 | $this->resolveTableNames($table, $name); |
||
154 | |||
155 | if ($this->findColumns($table)) { |
||
156 | $this->findConstraints($table); |
||
157 | |||
158 | return $table; |
||
159 | } |
||
160 | |||
161 | return null; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Loads a primary key for the given table. |
||
166 | * |
||
167 | * @param string $tableName table name. |
||
168 | * |
||
169 | * @throws Exception |
||
170 | * @throws InvalidArgumentException |
||
171 | * @throws InvalidConfigException |
||
172 | * |
||
173 | * @return Constraint|null primary key for the given table, `null` if the table has no primary key. |
||
174 | */ |
||
175 | protected function loadTablePrimaryKey(string $tableName): ?Constraint |
||
176 | { |
||
177 | return $this->loadTableConstraints($tableName, 'primaryKey'); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Loads all foreign keys for the given table. |
||
182 | * |
||
183 | * @param string $tableName table name. |
||
184 | * |
||
185 | * @throws Exception |
||
186 | * @throws InvalidArgumentException |
||
187 | * @throws InvalidConfigException |
||
188 | * |
||
189 | * @return ForeignKeyConstraint[] foreign keys for the given table. |
||
190 | */ |
||
191 | protected function loadTableForeignKeys(string $tableName): array |
||
192 | { |
||
193 | return $this->loadTableConstraints($tableName, 'foreignKeys'); |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * Loads all indexes for the given table. |
||
198 | * |
||
199 | * @param string $tableName table name. |
||
200 | * |
||
201 | * @throws Exception |
||
202 | * @throws InvalidArgumentException |
||
203 | * @throws InvalidConfigException |
||
204 | * |
||
205 | * @return IndexConstraint[] indexes for the given table. |
||
206 | */ |
||
207 | protected function loadTableIndexes(string $tableName): array |
||
208 | { |
||
209 | static $sql = <<<'SQL' |
||
210 | SELECT |
||
211 | `s`.`INDEX_NAME` AS `name`, |
||
212 | `s`.`COLUMN_NAME` AS `column_name`, |
||
213 | `s`.`NON_UNIQUE` ^ 1 AS `index_is_unique`, |
||
214 | `s`.`INDEX_NAME` = 'PRIMARY' AS `index_is_primary` |
||
215 | FROM `information_schema`.`STATISTICS` AS `s` |
||
216 | WHERE `s`.`TABLE_SCHEMA` = COALESCE(:schemaName, DATABASE()) AND `s`.`INDEX_SCHEMA` = `s`.`TABLE_SCHEMA` AND `s`.`TABLE_NAME` = :tableName |
||
217 | ORDER BY `s`.`SEQ_IN_INDEX` ASC |
||
218 | SQL; |
||
219 | |||
220 | $resolvedName = $this->resolveTableName($tableName); |
||
221 | |||
222 | $indexes = $this->getDb()->createCommand($sql, [ |
||
223 | ':schemaName' => $resolvedName->getSchemaName(), |
||
224 | ':tableName' => $resolvedName->getName(), |
||
225 | ])->queryAll(); |
||
226 | |||
227 | $indexes = $this->normalizePdoRowKeyCase($indexes, true); |
||
228 | $indexes = ArrayHelper::index($indexes, null, 'name'); |
||
229 | $result = []; |
||
230 | |||
231 | foreach ($indexes as $name => $index) { |
||
232 | $ic = new IndexConstraint(); |
||
233 | |||
234 | $ic->primary((bool) $index[0]['index_is_primary']); |
||
235 | $ic->unique((bool) $index[0]['index_is_unique']); |
||
236 | $ic->name($name !== 'PRIMARY' ? $name : null); |
||
237 | $ic->columnNames(ArrayHelper::getColumn($index, 'column_name')); |
||
238 | |||
239 | $result[] = $ic; |
||
240 | } |
||
241 | |||
242 | return $result; |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * Loads all unique constraints for the given table. |
||
247 | * |
||
248 | * @param string $tableName table name. |
||
249 | * |
||
250 | * @throws Exception |
||
251 | * @throws InvalidArgumentException |
||
252 | * @throws InvalidConfigException |
||
253 | * |
||
254 | * @return Constraint[] unique constraints for the given table. |
||
255 | */ |
||
256 | protected function loadTableUniques(string $tableName): array |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * Loads all check constraints for the given table. |
||
263 | * |
||
264 | * @param string $tableName table name. |
||
265 | * |
||
266 | * @throws NotSupportedException |
||
267 | * |
||
268 | * @return CheckConstraint[] check constraints for the given table. |
||
269 | */ |
||
270 | protected function loadTableChecks(string $tableName): array |
||
|
|||
271 | { |
||
272 | throw new NotSupportedException('MySQL does not support check constraints.'); |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Loads all default value constraints for the given table. |
||
277 | * |
||
278 | * @param string $tableName table name. |
||
279 | * |
||
280 | * @throws NotSupportedException |
||
281 | * |
||
282 | * @return DefaultValueConstraint[] default value constraints for the given table. |
||
283 | */ |
||
284 | protected function loadTableDefaultValues(string $tableName): array |
||
285 | { |
||
286 | throw new NotSupportedException('MySQL does not support default value constraints.'); |
||
287 | } |
||
288 | |||
289 | /** |
||
290 | * Creates a query builder for the MySQL database. |
||
291 | * |
||
292 | * @return QueryBuilder query builder instance |
||
293 | */ |
||
294 | public function createQueryBuilder(): QueryBuilder |
||
295 | { |
||
296 | return new QueryBuilder($this->getDb()); |
||
297 | } |
||
298 | |||
299 | /** |
||
300 | * Resolves the table name and schema name (if any). |
||
301 | * |
||
302 | * @param TableSchema $table the table metadata object. |
||
303 | * @param string $name the table name. |
||
304 | */ |
||
305 | protected function resolveTableNames($table, $name): void |
||
306 | { |
||
307 | $parts = explode('.', str_replace('`', '', $name)); |
||
308 | |||
309 | if (isset($parts[1])) { |
||
310 | $table->schemaName($parts[0]); |
||
311 | $table->name($parts[1]); |
||
312 | $table->fullName($table->getSchemaName() . '.' . $table->getName()); |
||
313 | } else { |
||
314 | $table->name($parts[0]); |
||
315 | $table->fullName($parts[0]); |
||
316 | } |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * Loads the column information into a {@see ColumnSchema} object. |
||
321 | * |
||
322 | * @param array $info column information. |
||
323 | * |
||
324 | * @return ColumnSchema the column schema object. |
||
325 | */ |
||
326 | protected function loadColumnSchema(array $info): ColumnSchema |
||
327 | { |
||
328 | $column = $this->createColumnSchema(); |
||
329 | |||
330 | $column->name($info['field']); |
||
331 | $column->allowNull($info['null'] === 'YES'); |
||
332 | $column->primaryKey(strpos($info['key'], 'PRI') !== false); |
||
333 | $column->autoIncrement(stripos($info['extra'], 'auto_increment') !== false); |
||
334 | $column->comment($info['comment']); |
||
335 | $column->dbType($info['type']); |
||
336 | $column->unsigned(stripos($column->getDbType(), 'unsigned') !== false); |
||
337 | $column->type(self::TYPE_STRING); |
||
338 | |||
339 | if (preg_match('/^(\w+)(?:\(([^)]+)\))?/', $column->getDbType(), $matches)) { |
||
340 | $type = strtolower($matches[1]); |
||
341 | |||
342 | if (isset($this->typeMap[$type])) { |
||
343 | $column->type($this->typeMap[$type]); |
||
344 | } |
||
345 | |||
346 | if (!empty($matches[2])) { |
||
347 | if ($type === 'enum') { |
||
348 | preg_match_all("/'[^']*'/", $matches[2], $values); |
||
349 | |||
350 | foreach ($values[0] as $i => $value) { |
||
351 | $values[$i] = trim($value, "'"); |
||
352 | } |
||
353 | |||
354 | $column->enumValues($values); |
||
355 | } else { |
||
356 | $values = explode(',', $matches[2]); |
||
357 | $column->precision((int) $values[0]); |
||
358 | $column->size((int) $values[0]); |
||
359 | |||
360 | if (isset($values[1])) { |
||
361 | $column->scale((int) $values[1]); |
||
362 | } |
||
363 | |||
364 | if ($column->getSize() === 1 && $type === 'tinyint') { |
||
365 | $column->type('boolean'); |
||
366 | } elseif ($type === 'bit') { |
||
367 | if ($column->getSize() > 32) { |
||
368 | $column->type('bigint'); |
||
369 | } elseif ($column->getSize() === 32) { |
||
370 | $column->type('integer'); |
||
371 | } |
||
372 | } |
||
373 | } |
||
374 | } |
||
375 | } |
||
376 | |||
377 | $column->phpType($this->getColumnPhpType($column)); |
||
378 | |||
379 | if (!$column->isPrimaryKey()) { |
||
380 | /** |
||
381 | * When displayed in the INFORMATION_SCHEMA.COLUMNS table, a default CURRENT TIMESTAMP is displayed |
||
382 | * as CURRENT_TIMESTAMP up until MariaDB 10.2.2, and as current_timestamp() from MariaDB 10.2.3. |
||
383 | * |
||
384 | * See details here: https://mariadb.com/kb/en/library/now/#description |
||
385 | */ |
||
386 | if ( |
||
387 | ($column->getType() === 'timestamp' || $column->getType() === 'datetime') |
||
388 | && preg_match('/^current_timestamp(?:\(([0-9]*)\))?$/i', (string) $info['default'], $matches) |
||
389 | ) { |
||
390 | $column->defaultValue(new Expression('CURRENT_TIMESTAMP' . (!empty($matches[1]) |
||
391 | ? '(' . $matches[1] . ')' : ''))); |
||
392 | } elseif (isset($type) && $type === 'bit') { |
||
393 | $column->defaultValue(bindec(trim((string) $info['default'], 'b\''))); |
||
394 | } else { |
||
395 | $column->defaultValue($column->phpTypecast($info['default'])); |
||
396 | } |
||
397 | } |
||
398 | |||
399 | return $column; |
||
400 | } |
||
401 | |||
402 | /** |
||
403 | * Collects the metadata of table columns. |
||
404 | * |
||
405 | * @param TableSchema $table the table metadata. |
||
406 | * |
||
407 | * @throws Exception if DB query fails. |
||
408 | * |
||
409 | * @return bool whether the table exists in the database. |
||
410 | */ |
||
411 | protected function findColumns($table): bool |
||
412 | { |
||
413 | $sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteTableName($table->getFullName()); |
||
414 | |||
415 | try { |
||
416 | $columns = $this->getDb()->createCommand($sql)->queryAll(); |
||
417 | } catch (Exception $e) { |
||
418 | $previous = $e->getPrevious(); |
||
419 | |||
420 | if ($previous instanceof PDOException && strpos($previous->getMessage(), 'SQLSTATE[42S02') !== false) { |
||
421 | /** |
||
422 | * table does not exist. |
||
423 | * |
||
424 | * https://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html#error_er_bad_table_error |
||
425 | */ |
||
426 | return false; |
||
427 | } |
||
428 | |||
429 | throw $e; |
||
430 | } |
||
431 | |||
432 | foreach ($columns as $info) { |
||
433 | if ($this->getDb()->getSlavePdo()->getAttribute(PDO::ATTR_CASE) !== PDO::CASE_LOWER) { |
||
434 | $info = array_change_key_case($info, CASE_LOWER); |
||
435 | } |
||
436 | |||
437 | $column = $this->loadColumnSchema($info); |
||
438 | $table->columns($column->getName(), $column); |
||
439 | |||
440 | if ($column->isPrimaryKey()) { |
||
441 | $table->primaryKey($column->getName()); |
||
442 | if ($column->isAutoIncrement()) { |
||
443 | $table->sequenceName(''); |
||
444 | } |
||
445 | } |
||
446 | } |
||
447 | |||
448 | return true; |
||
449 | } |
||
450 | |||
451 | /** |
||
452 | * Gets the CREATE TABLE sql string. |
||
453 | * |
||
454 | * @param TableSchema $table the table metadata. |
||
455 | * |
||
456 | * @throws Exception |
||
457 | * @throws InvalidArgumentException |
||
458 | * @throws InvalidConfigException |
||
459 | * |
||
460 | * @return string $sql the result of 'SHOW CREATE TABLE'. |
||
461 | */ |
||
462 | protected function getCreateTableSql($table): string |
||
463 | { |
||
464 | $row = $this->getDb()->createCommand( |
||
465 | 'SHOW CREATE TABLE ' . $this->quoteTableName($table->getFullName()) |
||
466 | )->queryOne(); |
||
467 | |||
468 | if (isset($row['Create Table'])) { |
||
469 | $sql = $row['Create Table']; |
||
470 | } else { |
||
471 | $row = array_values($row); |
||
472 | $sql = $row[1]; |
||
473 | } |
||
474 | |||
475 | return $sql; |
||
476 | } |
||
477 | |||
478 | /** |
||
479 | * Collects the foreign key column details for the given table. |
||
480 | * |
||
481 | * @param TableSchema $table the table metadata. |
||
482 | * |
||
483 | * @throws Exception |
||
484 | */ |
||
485 | protected function findConstraints($table) |
||
486 | { |
||
487 | $sql = <<<'SQL' |
||
488 | SELECT |
||
489 | `kcu`.`CONSTRAINT_NAME` AS `constraint_name`, |
||
490 | `kcu`.`COLUMN_NAME` AS `column_name`, |
||
491 | `kcu`.`REFERENCED_TABLE_NAME` AS `referenced_table_name`, |
||
492 | `kcu`.`REFERENCED_COLUMN_NAME` AS `referenced_column_name` |
||
493 | FROM `information_schema`.`REFERENTIAL_CONSTRAINTS` AS `rc` |
||
494 | JOIN `information_schema`.`KEY_COLUMN_USAGE` AS `kcu` ON |
||
495 | ( |
||
496 | `kcu`.`CONSTRAINT_CATALOG` = `rc`.`CONSTRAINT_CATALOG` OR |
||
497 | (`kcu`.`CONSTRAINT_CATALOG` IS NULL AND `rc`.`CONSTRAINT_CATALOG` IS NULL) |
||
498 | ) AND |
||
499 | `kcu`.`CONSTRAINT_SCHEMA` = `rc`.`CONSTRAINT_SCHEMA` AND |
||
500 | `kcu`.`CONSTRAINT_NAME` = `rc`.`CONSTRAINT_NAME` |
||
501 | WHERE `rc`.`CONSTRAINT_SCHEMA` = database() AND `kcu`.`TABLE_SCHEMA` = database() |
||
502 | AND `rc`.`TABLE_NAME` = :tableName AND `kcu`.`TABLE_NAME` = :tableName1 |
||
503 | SQL; |
||
504 | |||
505 | try { |
||
506 | $rows = $this->getDb()->createCommand( |
||
507 | $sql, |
||
508 | [':tableName' => $table->getName(), ':tableName1' => $table->getName()] |
||
509 | )->queryAll(); |
||
510 | |||
511 | $constraints = []; |
||
512 | |||
513 | foreach ($rows as $row) { |
||
514 | $constraints[$row['constraint_name']]['referenced_table_name'] = $row['referenced_table_name']; |
||
515 | $constraints[$row['constraint_name']]['columns'][$row['column_name']] = $row['referenced_column_name']; |
||
516 | } |
||
517 | |||
518 | $table->foreignKeys([]); |
||
519 | |||
520 | foreach ($constraints as $name => $constraint) { |
||
521 | $table->foreignKey($name, array_merge( |
||
522 | [$constraint['referenced_table_name']], |
||
523 | $constraint['columns'] |
||
524 | )); |
||
525 | } |
||
526 | } catch (Exception $e) { |
||
527 | $previous = $e->getPrevious(); |
||
528 | |||
529 | if (!$previous instanceof PDOException || strpos($previous->getMessage(), 'SQLSTATE[42S02') === false) { |
||
530 | throw $e; |
||
531 | } |
||
532 | |||
533 | // table does not exist, try to determine the foreign keys using the table creation sql |
||
534 | $sql = $this->getCreateTableSql($table); |
||
535 | $regexp = '/FOREIGN KEY\s+\(([^\)]+)\)\s+REFERENCES\s+([^\(^\s]+)\s*\(([^\)]+)\)/mi'; |
||
536 | |||
537 | if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) { |
||
538 | foreach ($matches as $match) { |
||
539 | $fks = array_map('trim', explode(',', str_replace('`', '', $match[1]))); |
||
540 | $pks = array_map('trim', explode(',', str_replace('`', '', $match[3]))); |
||
541 | $constraint = [str_replace('`', '', $match[2])]; |
||
542 | |||
543 | foreach ($fks as $k => $name) { |
||
544 | $constraint[$name] = $pks[$k]; |
||
545 | } |
||
546 | |||
547 | $table->foreignKey(\md5(\serialize($constraint)), $constraint); |
||
548 | } |
||
549 | $table->foreignKeys(array_values($table->getForeignKeys())); |
||
550 | } |
||
551 | } |
||
552 | } |
||
553 | |||
554 | /** |
||
555 | * Returns all unique indexes for the given table. |
||
556 | * |
||
557 | * Each array element is of the following structure: |
||
558 | * |
||
559 | * ```php |
||
560 | * [ |
||
561 | * 'IndexName1' => ['col1' [, ...]], |
||
562 | * 'IndexName2' => ['col2' [, ...]], |
||
563 | * ] |
||
564 | * ``` |
||
565 | * |
||
566 | * @param TableSchema $table the table metadata. |
||
567 | * |
||
568 | * @throws Exception |
||
569 | * @throws InvalidArgumentException |
||
570 | * @throws InvalidConfigException |
||
571 | * |
||
572 | * @return array all unique indexes for the given table. |
||
573 | */ |
||
574 | public function findUniqueIndexes($table): array |
||
575 | { |
||
576 | $sql = $this->getCreateTableSql($table); |
||
577 | |||
578 | $uniqueIndexes = []; |
||
579 | |||
580 | $regexp = '/UNIQUE KEY\s+\`(.+)\`\s*\((\`.+\`)+\)/mi'; |
||
581 | |||
582 | if (preg_match_all($regexp, $sql, $matches, PREG_SET_ORDER)) { |
||
583 | foreach ($matches as $match) { |
||
584 | $indexName = $match[1]; |
||
585 | $indexColumns = array_map('trim', explode('`,`', trim($match[2], '`'))); |
||
586 | $uniqueIndexes[$indexName] = $indexColumns; |
||
587 | } |
||
588 | } |
||
589 | |||
590 | return $uniqueIndexes; |
||
591 | } |
||
592 | |||
593 | /** |
||
594 | * Create a column schema builder instance giving the type and value precision. |
||
595 | * |
||
596 | * This method may be overridden by child classes to create a DBMS-specific column schema builder. |
||
597 | * |
||
598 | * @param string $type type of the column. See {@see ColumnSchemaBuilder::$type}. |
||
599 | * @param int|string|array $length length or precision of the column. See {@see ColumnSchemaBuilder::$length}. |
||
600 | * |
||
601 | * @return ColumnSchemaBuilder column schema builder instance |
||
602 | */ |
||
603 | public function createColumnSchemaBuilder(string $type, $length = null): ColumnSchemaBuilder |
||
604 | { |
||
605 | return new ColumnSchemaBuilder($type, $length, $this->getDb()); |
||
606 | } |
||
607 | |||
608 | /** |
||
609 | * @throws InvalidConfigException |
||
610 | * @throws Exception |
||
611 | * |
||
612 | * @return bool whether the version of the MySQL being used is older than 5.1. |
||
613 | */ |
||
614 | protected function isOldMysql(): bool |
||
623 | } |
||
624 | |||
625 | /** |
||
626 | * Loads multiple types of constraints and returns the specified ones. |
||
627 | * |
||
628 | * @param string $tableName table name. |
||
629 | * @param string $returnType return type: |
||
630 | * - primaryKey |
||
631 | * - foreignKeys |
||
632 | * - uniques |
||
633 | * |
||
634 | * @throws Exception |
||
635 | * @throws InvalidArgumentException |
||
636 | * @throws InvalidConfigException |
||
637 | * |
||
638 | * @return mixed constraints. |
||
639 | */ |
||
640 | private function loadTableConstraints(string $tableName, string $returnType) |
||
743 | } |
||
744 | |||
745 | /** |
||
746 | * Creates a column schema for the database. |
||
747 | * |
||
748 | * This method may be overridden by child classes to create a DBMS-specific column schema. |
||
749 | * |
||
750 | * @return ColumnSchema column schema instance. |
||
751 | */ |
||
752 | private function createColumnSchema(): ColumnSchema |
||
755 | } |
||
756 | } |
||
757 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.