Skip to content

Commit

Permalink
Declare internal properties of SchemaDiff as private
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Oct 16, 2022
1 parent 146ae85 commit bc4a07a
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 143 deletions.
14 changes: 7 additions & 7 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): SchemaDiff
continue;
}

$createdSchemas[$namespace] = $namespace;
$createdSchemas[] = $namespace;
}

foreach ($fromSchema->getNamespaces() as $namespace) {
if ($toSchema->hasNamespace($namespace)) {
continue;
}

$droppedSchemas[$namespace] = $namespace;
$droppedSchemas[] = $namespace;
}

foreach ($toSchema->getTables() as $table) {
$tableName = $table->getShortestName($toSchema->getName());
if (! $fromSchema->hasTable($tableName)) {
$createdTables[$tableName] = $toSchema->getTable($tableName);
$createdTables[] = $toSchema->getTable($tableName);
} else {
$tableDifferences = $this->diffTable(
$fromSchema->getTable($tableName),
$toSchema->getTable($tableName),
);

if ($tableDifferences !== null) {
$alteredTables[$tableName] = $tableDifferences;
$alteredTables[] = $tableDifferences;
}
}
}
Expand All @@ -77,7 +77,7 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): SchemaDiff
continue;
}

$droppedTables[$tableName] = $table;
$droppedTables[] = $table;
}

foreach ($toSchema->getSequences() as $sequence) {
Expand Down Expand Up @@ -108,11 +108,11 @@ public function compareSchemas(Schema $fromSchema, Schema $toSchema): SchemaDiff
}

return new SchemaDiff(
$createdSchemas,
$droppedSchemas,
$createdTables,
$alteredTables,
$droppedTables,
$createdSchemas,
$droppedSchemas,
$createdSequences,
$alteredSequences,
$droppedSequences,
Expand Down
95 changes: 24 additions & 71 deletions src/Schema/SchemaDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,125 +14,78 @@
*/
class SchemaDiff
{
/**
* All added namespaces.
*
* @internal Use {@link getCreatedSchemas()} instead.
*
* @var array<string, string>
*/
public array $newNamespaces = [];

/**
* All removed namespaces.
*
* @internal Use {@link getDroppedSchemas()} instead.
*
* @var array<string, string>
*/
public array $removedNamespaces = [];

/**
* @internal Use {@link getCreatedSequences()} instead.
*
* @var array<int, Sequence>
*/
public array $newSequences = [];

/**
* @internal Use {@link getAlteredSequences()} instead.
*
* @var array<int, Sequence>
*/
public array $changedSequences = [];

/**
* @internal Use {@link getDroppedSequences()} instead.
*
* @var array<int, Sequence>
*/
public array $removedSequences = [];

/**
* Constructs an SchemaDiff object.
*
* @internal The diff can be only instantiated by a {@see Comparator}.
*
* @param array<string, Table> $newTables
* @param array<string, TableDiff> $changedTables
* @param array<string, Table> $removedTables
* @param array<string> $createdSchemas
* @param array<string> $droppedSchemas
* @param array<Sequence> $createdSequences
* @param array<Sequence> $alteredSequences
* @param array<Sequence> $droppedSequences
* @param array<string> $createdSchemas
* @param array<string> $droppedSchemas
* @param array<Table> $createdTables
* @param array<TableDiff> $alteredTables
* @param array<Table> $droppedTables
* @param array<Sequence> $createdSequences
* @param array<Sequence> $alteredSequences
* @param array<Sequence> $droppedSequences
*/
public function __construct(
/** @internal Use {@link getCreatedTables()} instead. */
public array $newTables = [],
/** @internal Use {@link getAlteredTables()} instead. */
public array $changedTables = [],
/** @internal Use {@link getDroppedTables()} instead. */
public array $removedTables = [],
array $createdSchemas = [],
array $droppedSchemas = [],
array $createdSequences = [],
array $alteredSequences = [],
array $droppedSequences = [],
private readonly array $createdSchemas,
private readonly array $droppedSchemas,
private readonly array $createdTables,
private readonly array $alteredTables,
private readonly array $droppedTables,
private readonly array $createdSequences,
private readonly array $alteredSequences,
private readonly array $droppedSequences,
) {
$this->newNamespaces = $createdSchemas;
$this->removedNamespaces = $droppedSchemas;
$this->newSequences = $createdSequences;
$this->changedSequences = $alteredSequences;
$this->removedSequences = $droppedSequences;
}

/** @return array<string> */
public function getCreatedSchemas(): array
{
return $this->newNamespaces;
return $this->createdSchemas;
}

/** @return array<string> */
public function getDroppedSchemas(): array
{
return $this->removedNamespaces;
return $this->droppedSchemas;
}

/** @return array<Table> */
public function getCreatedTables(): array
{
return $this->newTables;
return $this->createdTables;
}

/** @return array<TableDiff> */
public function getAlteredTables(): array
{
return $this->changedTables;
return $this->alteredTables;
}

/** @return array<Table> */
public function getDroppedTables(): array
{
return $this->removedTables;
return $this->droppedTables;
}

/** @return array<Sequence> */
public function getCreatedSequences(): array
{
return $this->newSequences;
return $this->createdSequences;
}

/** @return array<Sequence> */
public function getAlteredSequences(): array
{
return $this->changedSequences;
return $this->alteredSequences;
}

/** @return array<Sequence> */
public function getDroppedSequences(): array
{
return $this->removedSequences;
return $this->droppedSequences;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,7 @@ public function testTableInNamespace(): void
self::markTestSkipped('Schema definition is not supported by this platform.');
}

//create schema
$diff = new SchemaDiff();
$diff->newNamespaces['testschema'] = 'testschema';
$diff = new SchemaDiff(['testschema'], [], [], [], [], [], [], []);

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

0 comments on commit bc4a07a

Please sign in to comment.