diff --git a/src/Platforms/MySQL/Comparator.php b/src/Platforms/MySQL/Comparator.php index 6be36be67a9..ebe025dc2a9 100644 --- a/src/Platforms/MySQL/Comparator.php +++ b/src/Platforms/MySQL/Comparator.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Schema\Comparator as BaseComparator; -use Doctrine\DBAL\Schema\ComparatorConfig; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; @@ -31,12 +30,11 @@ public function __construct( parent::__construct($platform); } - public function compareTables(Table $oldTable, Table $newTable, ?ComparatorConfig $config = null): TableDiff + public function compareTables(Table $oldTable, Table $newTable): TableDiff { return parent::compareTables( $this->normalizeTable($oldTable), $this->normalizeTable($newTable), - $config, ); } diff --git a/src/Platforms/SQLServer/Comparator.php b/src/Platforms/SQLServer/Comparator.php index 5135b508b4f..aa8d9fb5b62 100644 --- a/src/Platforms/SQLServer/Comparator.php +++ b/src/Platforms/SQLServer/Comparator.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\Comparator as BaseComparator; -use Doctrine\DBAL\Schema\ComparatorConfig; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; @@ -23,12 +22,11 @@ public function __construct(SQLServerPlatform $platform, private readonly string parent::__construct($platform); } - public function compareTables(Table $oldTable, Table $newTable, ?ComparatorConfig $config = null): TableDiff + public function compareTables(Table $oldTable, Table $newTable): TableDiff { return parent::compareTables( $this->normalizeColumns($oldTable), $this->normalizeColumns($newTable), - $config, ); } diff --git a/src/Platforms/SQLite/Comparator.php b/src/Platforms/SQLite/Comparator.php index 4c1f0475c97..f27e1b4571c 100644 --- a/src/Platforms/SQLite/Comparator.php +++ b/src/Platforms/SQLite/Comparator.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\SQLitePlatform; use Doctrine\DBAL\Schema\Comparator as BaseComparator; -use Doctrine\DBAL\Schema\ComparatorConfig; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\TableDiff; @@ -25,12 +24,11 @@ public function __construct(SQLitePlatform $platform) parent::__construct($platform); } - public function compareTables(Table $oldTable, Table $newTable, ?ComparatorConfig $config = null): TableDiff + public function compareTables(Table $oldTable, Table $newTable): TableDiff { return parent::compareTables( $this->normalizeColumns($oldTable), $this->normalizeColumns($newTable), - $config, ); } diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 88710f84f6e..b5b0b1ea130 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -16,15 +16,23 @@ */ class Comparator { + private ComparatorConfig $config; + /** @internal The comparator can be only instantiated by a schema manager. */ public function __construct(private readonly AbstractPlatform $platform) { + $this->config = new ComparatorConfig(); + } + + public function setConfig(ComparatorConfig $config): void + { + $this->config = $config; } /** * Returns the differences between the schemas. */ - public function compareSchemas(Schema $oldSchema, Schema $newSchema, ?ComparatorConfig $config = null): SchemaDiff + public function compareSchemas(Schema $oldSchema, Schema $newSchema): SchemaDiff { $createdSchemas = []; $droppedSchemas = []; @@ -59,7 +67,6 @@ public function compareSchemas(Schema $oldSchema, Schema $newSchema, ?Comparator $tableDiff = $this->compareTables( $oldSchema->getTable($newTableName), $newSchema->getTable($newTableName), - $config, ); if (! $tableDiff->isEmpty()) { @@ -142,10 +149,8 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2): bool /** * Compares the tables and returns the difference between them. */ - public function compareTables(Table $oldTable, Table $newTable, ?ComparatorConfig $config = null): TableDiff + public function compareTables(Table $oldTable, Table $newTable): TableDiff { - $config ??= new ComparatorConfig(); - $addedColumns = []; $modifiedColumns = []; $droppedColumns = []; @@ -192,7 +197,7 @@ public function compareTables(Table $oldTable, Table $newTable, ?ComparatorConfi $modifiedColumns[] = new ColumnDiff($oldColumn, $newColumn); } - if ($config->getDetectRenamedColumns()) { + if ($this->config->getDetectRenamedColumns()) { $renamedColumns = $this->detectRenamedColumns($addedColumns, $droppedColumns); } @@ -231,7 +236,7 @@ public function compareTables(Table $oldTable, Table $newTable, ?ComparatorConfi $modifiedIndexes[] = $newIndex; } - if ($config->getDetectRenamedIndexes()) { + if ($this->config->getDetectRenamedIndexes()) { $renamedIndexes = $this->detectRenamedIndexes($addedIndexes, $droppedIndexes); } diff --git a/tests/Schema/AbstractComparatorTestCase.php b/tests/Schema/AbstractComparatorTestCase.php index cdc5740742e..eb41ba914b7 100644 --- a/tests/Schema/AbstractComparatorTestCase.php +++ b/tests/Schema/AbstractComparatorTestCase.php @@ -406,7 +406,8 @@ public function testDetectRenameColumnDisabled(): void $config = new ComparatorConfig(); $config->setDetectRenamedColumns(false); - $tableDiff = $this->comparator->compareTables($tableA, $tableB, $config); + $this->comparator->setConfig($config); + $tableDiff = $this->comparator->compareTables($tableA, $tableB); self::assertCount(1, $tableDiff->getAddedColumns()); self::assertCount(1, $tableDiff->getDroppedColumns()); @@ -468,7 +469,8 @@ public function testDetectRenameIndexDisabled(): void $config = new ComparatorConfig(); $config->setDetectRenamedIndexes(false); - $tableDiff = $this->comparator->compareTables($table1, $table2, $config); + $this->comparator->setConfig($config); + $tableDiff = $this->comparator->compareTables($table1, $table2); self::assertCount(1, $tableDiff->getAddedIndexes()); self::assertCount(1, $tableDiff->getDroppedIndexes());