Skip to content

Commit

Permalink
Remove deprecated Comparator::compare()
Browse files Browse the repository at this point in the history
The method has been deprecated and scheduled for removal since #4707.
  • Loading branch information
trompette committed Jul 16, 2021
1 parent d845b3d commit 14b57f6
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 145 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ awareness about deprecated code.

# Upgrade to 4.0

## Removed static keyword from `Comparator::compareSchemas()` signature

The method `Comparator::compareSchemas()` cannot be called statically anymore.

## Removed `Comparator::compare()`

The method `Comparator::compare()` has been removed, use `Comparator::compareSchemas()` instead.

## Removed `TableGenerator` component

The `TableGenerator` component has been removed.
Expand Down
8 changes: 0 additions & 8 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ parameters:
paths:
- %currentWorkingDirectory%/src/Driver/OCI8/Statement.php

# See https://github.com/doctrine/dbal/pull/4707
# TODO: remove in 4.0.0
-
message: '~^Dynamic call to static method Doctrine\\DBAL\\Schema\\Comparator::compareSchemas\(\)\.$~'
paths:
- %currentWorkingDirectory%/src/Schema/AbstractSchemaManager.php
- %currentWorkingDirectory%/src/Schema/Comparator.php
- %currentWorkingDirectory%/src/Schema/Schema.php
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
7 changes: 0 additions & 7 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@
-->
<referencedMethod name="Doctrine\DBAL\Query\QueryBuilder::execute"/>
<referencedMethod name="Doctrine\DBAL\Statement::execute"/>
<!--
See https://github.com/doctrine/dbal/pull/4707
TODO: remove in 4.0.0
-->
<file name="src/Schema/Comparator.php" />
<file name="tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php" />
<file name="tests/Schema/ComparatorTest.php" />
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction>
Expand Down
32 changes: 5 additions & 27 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Types;
use Doctrine\Deprecations\Deprecation;

use function array_intersect_key;
use function array_key_exists;
Expand All @@ -26,13 +25,10 @@ class Comparator
/**
* Returns a SchemaDiff object containing the differences between the schemas $fromSchema and $toSchema.
*
* This method should be called non-statically since it will be declared as non-static in the next major release.
*
* @throws SchemaException
*/
public static function compareSchemas(Schema $fromSchema, Schema $toSchema): SchemaDiff
public function compareSchemas(Schema $fromSchema, Schema $toSchema): SchemaDiff
{
$comparator = new self();
$diff = new SchemaDiff();
$diff->fromSchema = $fromSchema;

Expand All @@ -59,7 +55,7 @@ public static function compareSchemas(Schema $fromSchema, Schema $toSchema): Sch
if (! $fromSchema->hasTable($tableName)) {
$diff->newTables[$tableName] = $toSchema->getTable($tableName);
} else {
$tableDifferences = $comparator->diffTable(
$tableDifferences = $this->diffTable(
$fromSchema->getTable($tableName),
$toSchema->getTable($tableName)
);
Expand Down Expand Up @@ -120,18 +116,18 @@ public static function compareSchemas(Schema $fromSchema, Schema $toSchema): Sch
foreach ($toSchema->getSequences() as $sequence) {
$sequenceName = $sequence->getShortestName($toSchema->getName());
if (! $fromSchema->hasSequence($sequenceName)) {
if (! $comparator->isAutoIncrementSequenceInSchema($fromSchema, $sequence)) {
if (! $this->isAutoIncrementSequenceInSchema($fromSchema, $sequence)) {
$diff->newSequences[] = $sequence;
}
} else {
if ($comparator->diffSequence($sequence, $fromSchema->getSequence($sequenceName))) {
if ($this->diffSequence($sequence, $fromSchema->getSequence($sequenceName))) {
$diff->changedSequences[] = $toSchema->getSequence($sequenceName);
}
}
}

foreach ($fromSchema->getSequences() as $sequence) {
if ($comparator->isAutoIncrementSequenceInSchema($toSchema, $sequence)) {
if ($this->isAutoIncrementSequenceInSchema($toSchema, $sequence)) {
continue;
}

Expand All @@ -147,24 +143,6 @@ public static function compareSchemas(Schema $fromSchema, Schema $toSchema): Sch
return $diff;
}

/**
* @deprecated Use non-static call to {@link compareSchemas()} instead.
*
* @return SchemaDiff
*
* @throws SchemaException
*/
public function compare(Schema $fromSchema, Schema $toSchema)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4707',
'Method compare() is deprecated. Use a non-static call to compareSchemas() instead.'
);

return $this->compareSchemas($fromSchema, $toSchema);
}

private function isAutoIncrementSequenceInSchema(Schema $schema, Sequence $sequence): bool
{
foreach ($schema->getTables() as $table) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testAlterPrimaryKeyToAutoIncrementColumn(): void
$newTable->dropPrimaryKey();
$newTable->setPrimaryKey(['new_id']);

$diff = (new Comparator())->compare($schema, $newSchema);
$diff = (new Comparator())->compareSchemas($schema, $newSchema);

foreach ($diff->toSql($this->getPlatform()) as $sql) {
$this->connection->executeStatement($sql);
Expand Down
Loading

0 comments on commit 14b57f6

Please sign in to comment.