Skip to content

Commit

Permalink
Improve deprecation layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Nov 6, 2023
1 parent 6bbd2aa commit 686f7c5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 25 deletions.
8 changes: 8 additions & 0 deletions src/Schema/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,4 +463,12 @@ public function toArray()
'comment' => $this->_comment,
], $this->_platformOptions, $this->_customSchemaOptions);
}

public function cloneWithName(string $name): Column

Check warning on line 467 in src/Schema/Column.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Column.php#L467

Added line #L467 was not covered by tests
{
$clone = clone $this;
$clone->_setName($name);

Check warning on line 470 in src/Schema/Column.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Column.php#L469-L470

Added lines #L469 - L470 were not covered by tests

return $clone;

Check warning on line 472 in src/Schema/Column.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/Column.php#L472

Added line #L472 was not covered by tests
}
}
80 changes: 55 additions & 25 deletions src/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ class TableDiff
*
* @internal The diff can be only instantiated by a {@see Comparator}.
*
* @param string $tableName
* @param array<Column> $addedColumns
* @param array<ColumnDiff> $modifiedColumns
* @param array<Column> $droppedColumns
Expand All @@ -156,18 +155,18 @@ class TableDiff
* @param array<string,Index> $renamedIndexes
*/
public function __construct(
$tableName,
$addedColumns = [],
$modifiedColumns = [],
$droppedColumns = [],
$addedIndexes = [],
$changedIndexes = [],
$removedIndexes = [],
string $tableName,
array $addedColumns = [],
array $modifiedColumns = [],
array $droppedColumns = [],
array $addedIndexes = [],
array $changedIndexes = [],
array $removedIndexes = [],
?Table $fromTable = null,
$addedForeignKeys = [],
$changedForeignKeys = [],
$removedForeignKeys = [],
$renamedIndexes = []
array $addedForeignKeys = [],
array $changedForeignKeys = [],
array $removedForeignKeys = [],
array $renamedIndexes = []
) {
$this->name = $tableName;
$this->addedColumns = $addedColumns;
Expand Down Expand Up @@ -200,18 +199,50 @@ public function __construct(
/** @var array<string, Column> $renamedColumns */
$renamedColumns = $renamedIndexes;

Check warning on line 200 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L200

Added line #L200 was not covered by tests

$legacyChangedColumns = [];
foreach ($renamedColumns as $oldName => $column) {
$legacyChangedColumns[$oldName] = new ColumnDiff($oldName, $column, []);
}

$this->changedColumns = array_merge($this->changedColumns, $legacyChangedColumns);
$this->changedColumns = array_merge(
$this->changedColumns,
$this->convertLegacyRenamedColumn($renamedColumns),
);
$this->renamedIndexes = func_num_args() > 12 ? func_get_arg(13) : [];

Check warning on line 206 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L202-L206

Added lines #L202 - L206 were not covered by tests
}

$this->fromTable = $fromTable;
}

/**
* @param array<string, Column> $renamedColumns
*
* @return array<ColumnDiff>
*/
private function convertLegacyRenamedColumn(array $renamedColumns): array

Check warning on line 217 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L217

Added line #L217 was not covered by tests
{
$converted = [];
$changedColumns = [];
foreach ($this->changedColumns as $column) {
$oldName = isset($column->fromColumn)
? $column->fromColumn->getName()
: $column->oldColumnName;
$changedColumns[$oldName] = $column;

Check warning on line 225 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L219-L225

Added lines #L219 - L225 were not covered by tests
}

foreach ($renamedColumns as $oldName => $column) {
if (isset($changedColumns[$oldName])) {
$existingCol = $changedColumns[$oldName];
$column = $existingCol->getNewColumn()->cloneWithName($column->getName());
$converted[] = new ColumnDiff(
$oldName,
$column,
$existingCol->changedProperties,
$existingCol->getOldColumn(),
);

Check warning on line 237 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L228-L237

Added lines #L228 - L237 were not covered by tests
} else {
$converted[] = new ColumnDiff($oldName, $column, []);

Check warning on line 239 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L239

Added line #L239 was not covered by tests
}
}

return $converted;

Check warning on line 243 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L243

Added line #L243 was not covered by tests
}

/**
* @deprecated Use {@see getOldTable()} instead.
*
Expand Down Expand Up @@ -277,7 +308,7 @@ public function getModifiedColumns(): array
}));
}

/** @return list<ColumnDiff> */
/** @return array<ColumnDiff> */
public function getChangedColumns(): array
{
if (count($this->renamedColumns) > 0) {
Expand All @@ -289,12 +320,11 @@ public function getChangedColumns(): array
__METHOD__,
);

Check warning on line 321 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L315-L321

Added lines #L315 - L321 were not covered by tests

$legacyChangedColumns = [];
foreach ($this->renamedColumns as $oldName => $column) {
$legacyChangedColumns[$oldName] = new ColumnDiff($oldName, $column, []);
}

return array_values(array_merge($this->changedColumns, $legacyChangedColumns));
$this->changedColumns = array_merge(
$this->changedColumns,
$this->convertLegacyRenamedColumn($this->renamedColumns),
);
$this->renamedColumns = [];

Check warning on line 327 in src/Schema/TableDiff.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L323-L327

Added lines #L323 - L327 were not covered by tests
}

return array_values($this->changedColumns);
Expand Down

0 comments on commit 686f7c5

Please sign in to comment.