Skip to content

Commit

Permalink
Replace DbArrayHelper::getColumn() with array_column() (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Jan 31, 2025
1 parent 76ef139 commit 8d44f35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
- Enh #367: Use `ColumnDefinitionBuilder` to generate table column SQL representation (@Tigrov)
- Enh #371: Remove `ColumnInterface` (@Tigrov)
- Enh #372: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)
- Enh #373: Replace `DbArrayHelper::getColumn()` with `array_column()` (@Tigrov)

## 1.2.0 March 21, 2024

Expand Down
11 changes: 6 additions & 5 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Yiisoft\Db\Schema\TableSchemaInterface;

use function array_change_key_case;
use function array_column;
use function array_map;
use function array_values;
use function in_array;
Expand Down Expand Up @@ -533,21 +534,21 @@ private function loadTableConstraints(string $tableName, string $returnType): ar
switch ($type) {
case 'PRIMARY KEY':
$result[self::PRIMARY_KEY] = (new Constraint())
->columnNames(DbArrayHelper::getColumn($constraint, 'column_name'));
->columnNames(array_column($constraint, 'column_name'));
break;
case 'FOREIGN KEY':
$result[self::FOREIGN_KEYS][] = (new ForeignKeyConstraint())
->foreignSchemaName($constraint[0]['foreign_table_schema'])
->foreignTableName($constraint[0]['foreign_table_name'])
->foreignColumnNames(DbArrayHelper::getColumn($constraint, 'foreign_column_name'))
->foreignColumnNames(array_column($constraint, 'foreign_column_name'))
->onDelete($constraint[0]['on_delete'])
->onUpdate($constraint[0]['on_update'])
->columnNames(DbArrayHelper::getColumn($constraint, 'column_name'))
->columnNames(array_column($constraint, 'column_name'))
->name($name);
break;
case 'UNIQUE':
$result[self::UNIQUES][] = (new Constraint())
->columnNames(DbArrayHelper::getColumn($constraint, 'column_name'))
->columnNames(array_column($constraint, 'column_name'))
->name($name);
break;
}
Expand Down Expand Up @@ -640,7 +641,7 @@ protected function loadTableIndexes(string $tableName): array
$ic->primary((bool) $index[0]['index_is_primary']);
$ic->unique((bool) $index[0]['index_is_unique']);
$ic->name($name !== 'PRIMARY' ? $name : null);
$ic->columnNames(DbArrayHelper::getColumn($index, 'column_name'));
$ic->columnNames(array_column($index, 'column_name'));

$result[] = $ic;
}
Expand Down

0 comments on commit 8d44f35

Please sign in to comment.