Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace DbArrayHelper::getColumn() with array_column() #373

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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