Skip to content

Commit

Permalink
Change instances of TheType|false to TheType|null.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed May 28, 2019
1 parent 57a9d5c commit 8449ce3
Show file tree
Hide file tree
Showing 24 changed files with 40 additions and 45 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Upgrade to 3.0

## BC BREAK: Changes in the `Doctrine\DBAL\Schema` API

- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableViewDefinition()` now optionally returns null instead of false.
- Method `Doctrine\DBAL\Schema\Comparator::diffTable()` now optionally returns null instead of false.
- Property `Doctrine\DBAL\Schema\TableDiff::$newName` is now optionally null instead of false.

## BC BREAK: Changes in the `Doctrine\DBAL\Driver` API

1. The `$username` and `$password` arguments of `::connect()` are no longer nullable. Use an empty string to indicate empty username or password.
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1932,7 +1932,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
$sql = [];
$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$tableName = $newName->getQuotedName($this);
} else {
$tableName = $diff->getName($this)->getQuotedName($this);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/DB2Platform.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ public function getAlterTableSQL(TableDiff $diff)

$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'RENAME TABLE %s TO %s',
$diff->getName($this)->getQuotedName($this),
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ public function getAlterTableSQL(TableDiff $diff)
$queryParts = [];
$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this);
}

Expand Down Expand Up @@ -835,7 +835,7 @@ protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff)
$sql = [];
$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$tableName = $newName->getQuotedName($this);
} else {
$tableName = $diff->getName($this)->getQuotedName($this);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ public function getAlterTableSQL(TableDiff $diff)

$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this),
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ public function getAlterTableSQL(TableDiff $diff)

$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this),
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function getAlterTableSQL(TableDiff $diff)

$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' .
$this->getAlterTableRenameTableClause($newName);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ public function getAlterTableSQL(TableDiff $diff)

$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'";

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff)
$sql = [];
$tableName = $diff->getNewName();

if ($tableName === false) {
if ($tableName === null) {
$tableName = $diff->getName($this);
}

Expand Down Expand Up @@ -911,7 +911,7 @@ public function getAlterTableSQL(TableDiff $diff)

$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$newTable->getQuotedName($this),
Expand Down Expand Up @@ -993,7 +993,7 @@ private function getSimpleAlterTableSQL(TableDiff $diff)
}

if (! $this->onSchemaAlterTable($diff, $tableSql)) {
if ($diff->newName !== false) {
if ($diff->newName !== null) {
$newTable = new Identifier($diff->newName);
$sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' RENAME TO ' . $newTable->getQuotedName($this);
}
Expand Down
8 changes: 3 additions & 5 deletions lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ protected function _getPortableViewsList(array $views) : array
foreach ($views as $value) {
$view = $this->_getPortableViewDefinition($value);

if (! $view) {
if ($view === null) {
continue;
}

Expand All @@ -885,12 +885,10 @@ protected function _getPortableViewsList(array $views) : array

/**
* @param array<string, mixed> $view
*
* @return View|false
*/
protected function _getPortableViewDefinition(array $view)
protected function _getPortableViewDefinition(array $view) : ?View
{
return false;
return null;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions lib/Doctrine/DBAL/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function compare(Schema $fromSchema, Schema $toSchema) : SchemaDiff
$diff->newTables[$tableName] = $toSchema->getTable($tableName);
} else {
$tableDifferences = $this->diffTable($fromSchema->getTable($tableName), $toSchema->getTable($tableName));
if ($tableDifferences !== false) {
if ($tableDifferences !== null) {
$diff->changedTables[$tableName] = $tableDifferences;
}
}
Expand Down Expand Up @@ -170,10 +170,8 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2) : bool
* Returns the difference between the tables $table1 and $table2.
*
* If there are no differences this method returns the boolean false.
*
* @return TableDiff|false
*/
public function diffTable(Table $table1, Table $table2)
public function diffTable(Table $table1, Table $table2) : ?TableDiff
{
$changes = 0;
$tableDifferences = new TableDiff($table1->getName());
Expand Down Expand Up @@ -279,7 +277,7 @@ public function diffTable(Table $table1, Table $table2)
$changes++;
}

return $changes ? $tableDifferences : false;
return $changes ? $tableDifferences : null;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/DB2SchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : a
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : ?View
{
$view = array_change_key_case($view, CASE_LOWER);
// sadly this still segfaults on PDO_IBM, see http://pecl.php.net/bugs/bug.php?id=17199
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : ?View
{
return new View($view['TABLE_NAME'], $view['VIEW_DEFINITION']);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function dropDatabase($database) : void
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : ?View
{
$view = array_change_key_case($view, CASE_LOWER);

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected function _getPortableTriggerDefinition($trigger)
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : ?View
{
return new View($view['schemaname'] . '.' . $view['viewname'], $view['definition']);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : ?View
{
$definition = preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def']);
assert(is_string($definition));
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ protected function getPortableNamespaceDefinition(array $namespace)
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : ?View
{
// @todo
return new View($view['name'], '');
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) : Column
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : ?View
{
return new View($view['name'], $view['sql']);
}
Expand Down
15 changes: 4 additions & 11 deletions lib/Doctrine/DBAL/Schema/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class TableDiff
/** @var string */
public $name = null;

/** @var string|false */
public $newName = false;
/** @var string|null */
public $newName = null;

/**
* All added fields.
Expand Down Expand Up @@ -137,15 +137,8 @@ public function getName(AbstractPlatform $platform) : Identifier
);
}

/**
* @return Identifier|false
*/
public function getNewName()
public function getNewName() : ?Identifier
{
if ($this->newName === false) {
return false;
}

return new Identifier($this->newName);
return $this->newName !== null ? new Identifier($this->newName) : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function testDefaultValueComparison(string $type, $value) : void

$onlineTable = $this->schemaManager->listTableDetails('default_value');

self::assertFalse($this->comparator->diffTable($table, $onlineTable));
self::assertNull($this->comparator->diffTable($table, $onlineTable));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ public function testDiffListTableColumns()
$comparator = new Comparator();
$diff = $comparator->diffTable($offlineTable, $onlineTable);

self::assertFalse($diff, 'No differences should be detected with the offline vs online schema.');
self::assertNull($diff, 'No differences should be detected with the offline vs online schema.');
}

public function testListTableIndexes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function testDiffListIntegerAutoincrementTableColumns($integerType, $unsi
if ($expectedComparatorDiff) {
self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff));
} else {
self::assertFalse($diff);
self::assertNull($diff);
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function testCompareColumnCompareCaseInsensitive()
$c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB);

self::assertFalse($tableDiff);
self::assertNull($tableDiff);
}

public function testCompareIndexBasedOnPropertiesNotName()
Expand Down Expand Up @@ -659,7 +659,7 @@ public function testCompareForeignKeyBasedOnPropertiesNotName()
$c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB);

self::assertFalse($tableDiff);
self::assertNull($tableDiff);
}

public function testCompareForeignKeyRestrictNoActionAreTheSame()
Expand Down
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testReturnsNewName()
{
$tableDiff = new TableDiff('foo');

self::assertFalse($tableDiff->getNewName());
self::assertNull($tableDiff->getNewName());

$tableDiff->newName = 'bar';

Expand Down

0 comments on commit 8449ce3

Please sign in to comment.