Skip to content

Commit

Permalink
Replace DbArrayHelper::getColumn() with array_column() (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Jan 31, 2025
1 parent 56ba72b commit 9997cd2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Enh #379: Remove `ColumnInterface` (@Tigrov)
- Enh #380: Rename `ColumnSchemaInterface` to `ColumnInterface` (@Tigrov)
- Enh #381: Add `ColumnDefinitionParser` class (@Tigrov)
- Enh #382: Replace `DbArrayHelper::getColumn()` with `array_column()` (@Tigrov)

## 1.3.0 March 21, 2024

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

use function array_change_key_case;
use function array_column;
use function array_map;
use function array_unique;
use function array_values;
Expand Down Expand Up @@ -326,7 +327,7 @@ protected function loadTableIndexes(string $tableName): array
foreach ($indexes as $name => $index) {
$ic = (new IndexConstraint())
->name($name)
->columnNames(DbArrayHelper::getColumn($index, 'column_name'))
->columnNames(array_column($index, 'column_name'))
->primary($index[0]['index_is_primary'])
->unique($index[0]['index_is_unique']);

Expand Down Expand Up @@ -871,7 +872,7 @@ private function loadTableConstraints(string $tableName, string $returnType): ar
case 'p':
$result[self::PRIMARY_KEY] = (new Constraint())
->name($name)
->columnNames(DbArrayHelper::getColumn($constraint, 'column_name'));
->columnNames(array_column($constraint, 'column_name'));
break;
case 'f':
$onDelete = $actionTypes[$constraint[0]['on_delete']] ?? null;
Expand All @@ -880,25 +881,25 @@ private function loadTableConstraints(string $tableName, string $returnType): ar
$result[self::FOREIGN_KEYS][] = (new ForeignKeyConstraint())
->name($name)
->columnNames(array_values(
array_unique(DbArrayHelper::getColumn($constraint, 'column_name'))
array_unique(array_column($constraint, 'column_name'))
))
->foreignSchemaName($constraint[0]['foreign_table_schema'])
->foreignTableName($constraint[0]['foreign_table_name'])
->foreignColumnNames(array_values(
array_unique(DbArrayHelper::getColumn($constraint, 'foreign_column_name'))
array_unique(array_column($constraint, 'foreign_column_name'))
))
->onDelete($onDelete)
->onUpdate($onUpdate);
break;
case 'u':
$result[self::UNIQUES][] = (new Constraint())
->name($name)
->columnNames(DbArrayHelper::getColumn($constraint, 'column_name'));
->columnNames(array_column($constraint, 'column_name'));
break;
case 'c':
$result[self::CHECKS][] = (new CheckConstraint())
->name($name)
->columnNames(DbArrayHelper::getColumn($constraint, 'column_name'))
->columnNames(array_column($constraint, 'column_name'))
->expression($constraint[0]['check_expr']);
break;
}
Expand Down

0 comments on commit 9997cd2

Please sign in to comment.