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 30d4dab commit b88a8b6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ public function getAlterTableSQL(TableDiff $diff)
$diff->getAddedForeignKeys(),
$diff->getModifiedForeignKeys(),
$diff->getDroppedForeignKeys(),
null,
$diff->getRenamedIndexes(),
);
}
Expand Down
1 change: 0 additions & 1 deletion src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ public function compareTables(Table $fromTable, Table $toTable): TableDiff
$addedForeignKeys,
$modifiedForeignKeys,
$droppedForeignKeys,
null,
$renamedIndexes,
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use function array_merge;
use function in_array;
use function preg_match;
use function sprintf;
use function strlen;
use function strtolower;

Expand Down
36 changes: 22 additions & 14 deletions src/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use function array_merge;
use function array_values;
use function count;
use function current;
use function func_get_args;

/**
* Table Diff.
Expand Down Expand Up @@ -135,8 +137,6 @@ class TableDiff
*/
public $fromTable;

private bool $wasRenamedInternalUsed = false;

/**
* Constructs a TableDiff object.
*
Expand All @@ -152,7 +152,6 @@ class TableDiff
* @param list<ForeignKeyConstraint> $addedForeignKeys
* @param list<ForeignKeyConstraint> $changedForeignKeys
* @param list<ForeignKeyConstraint|string> $removedForeignKeys
* @param array<string, Column>|null $renamedColumns
* @param array<string,Index> $renamedIndexes
*/
public function __construct(
Expand All @@ -167,7 +166,6 @@ public function __construct(
$addedForeignKeys = [],
$changedForeignKeys = [],
$removedForeignKeys = [],
$renamedColumns = null,
$renamedIndexes = []
) {
$this->name = $tableName;
Expand All @@ -191,15 +189,23 @@ public function __construct(
);
}

if ($renamedColumns !== null) {
if (count($renamedIndexes) > 0 && current($renamedIndexes) instanceof Column) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6080',
'Passing $renamedColumns to %s is deprecated and will be removed in the next major.',
__METHOD__,
);

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

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L193-L198

Added lines #L193 - L198 were not covered by tests
$this->renamedColumns = $renamedColumns;
$this->wasRenamedInternalUsed = true;
/** @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, []);

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

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L202-L204

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

$this->changedColumns = array_merge($this->changedColumns, $legacyChangedColumns);
$this->renamedIndexes = func_get_args()[13] ?? [];

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

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L207-L208

Added lines #L207 - L208 were not covered by tests
}

$this->fromTable = $fromTable;
Expand Down Expand Up @@ -273,22 +279,24 @@ public function getModifiedColumns(): array
/** @return list<ColumnDiff> */
public function getChangedColumns(): array
{
if (! $this->wasRenamedInternalUsed && count($this->renamedColumns) > 0) {
if (count($this->renamedColumns) > 0) {
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6080',
'Modifying $renamedColumns is deprecated, this property will be removed in the next major. ' .
'Set $modifiedColumns in the constructor instead',
__METHOD__,
);

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

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L283-L289

Added lines #L283 - L289 were not covered by tests
}

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

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

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L291-L293

Added lines #L291 - L293 were not covered by tests
}

return array_values(array_merge($this->changedColumns, $legacyChangedColumns));

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

View check run for this annotation

Codecov / codecov/patch

src/Schema/TableDiff.php#L296

Added line #L296 was not covered by tests
}

return array_values(array_merge($this->changedColumns, $legacyChangedColumns));
return array_values($this->changedColumns);
}

/** @return list<Column> */
Expand All @@ -298,7 +306,7 @@ public function getDroppedColumns(): array
}

/**
* @deprecated Use {@see getModifiedColumns()} instead.
* @internal Use {@see getModifiedColumns()} instead.
*
* @return array<string,Column>
*/
Expand Down

0 comments on commit b88a8b6

Please sign in to comment.