Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types to Schema namespace #3565

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Upgrade to 3.0

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

- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableViewDefinition()` no longer optionally returns false. It will always return a `Doctrine\DBAL\Schema\View` instance.
jwage marked this conversation as resolved.
Show resolved Hide resolved
- 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.
- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::tablesExist()` no longer accepts a string. Use `Doctrine\DBAL\Schema\AbstractSchemaManager::tableExists()` instead.
- Method `Doctrine\DBAL\Schema\OracleSchemaManager::createDatabase()` no longer accepts `null` for `$database` argument.
- Removed unused method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableFunctionsList()`
- Removed unused method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableFunctionDefinition()`
- Removed unused method `Doctrine\DBAL\Schema\OracleSchemaManager::_getPortableFunctionDefinition()`
- Removed unused method `Doctrine\DBAL\Schema\SqliteSchemaManager::_getPortableTableIndexDefinition()`

## 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
9 changes: 5 additions & 4 deletions lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
use function is_array;

/**
Expand All @@ -24,7 +23,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */
private $platform;

/** @var string[] */
/** @var array<int, string> */
private $sql = [];

public function __construct(Column $column, Table $table, AbstractPlatform $platform)
Expand Down Expand Up @@ -66,7 +65,9 @@ public function getPlatform()
public function addSql($sql)
{
if (is_array($sql)) {
$this->sql = array_merge($this->sql, $sql);
foreach ($sql as $query) {
$this->sql[] = $query;
}
} else {
$this->sql[] = $sql;
}
Expand All @@ -75,7 +76,7 @@ public function addSql($sql)
}

/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
{
Expand Down
7 changes: 4 additions & 3 deletions lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
use function is_array;

/**
Expand Down Expand Up @@ -81,7 +80,9 @@ public function getPlatform()
public function addSql($sql)
{
if (is_array($sql)) {
$this->sql = array_merge($this->sql, $sql);
foreach ($sql as $query) {
$this->sql[] = $query;
}
} else {
$this->sql[] = $sql;
}
Expand All @@ -90,7 +91,7 @@ public function addSql($sql)
}

/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
{
Expand Down
21 changes: 21 additions & 0 deletions lib/Doctrine/DBAL/Exception/DatabaseRequired.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Exception;

use Doctrine\DBAL\DBALException;
use function sprintf;

class DatabaseRequired extends DBALException
{
public static function new(string $methodName) : self
{
return new self(
sprintf(
'A database is required for the method: %s.',
$methodName
)
);
}
}
12 changes: 6 additions & 6 deletions lib/Doctrine/DBAL/Id/TableGeneratorSchemaVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct($generatorTableName = 'sequences')
/**
* {@inheritdoc}
*/
public function acceptSchema(Schema $schema)
public function acceptSchema(Schema $schema) : void
{
$table = $schema->createTable($this->generatorTableName);
$table->addColumn('sequence_name', 'string');
Expand All @@ -39,35 +39,35 @@ public function acceptSchema(Schema $schema)
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
}

/**
* {@inheritdoc}
*/
public function acceptColumn(Table $table, Column $column)
public function acceptColumn(Table $table, Column $column) : void
{
}

/**
* {@inheritdoc}
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{
}

/**
* {@inheritdoc}
*/
public function acceptIndex(Table $table, Index $index)
public function acceptIndex(Table $table, Index $index) : void
{
}

/**
* {@inheritdoc}
*/
public function acceptSequence(Sequence $sequence)
public function acceptSequence(Sequence $sequence) : void
{
}
}
10 changes: 5 additions & 5 deletions lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ public function getDropForeignKeySQL($foreignKey, $table) : string
* Returns the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform.
*
* @return string[] The sequence of SQL statements.
* @return array<int, string> The sequence of SQL statements.
*
* @throws DBALException
*/
Expand Down Expand Up @@ -1406,7 +1406,7 @@ public function getInlineColumnCommentSQL(?string $comment) : string
* @param mixed[][] $columns
* @param mixed[] $options
*
* @return string[]
* @return array<int, string>
*/
protected function _getCreateTableSQL(string $tableName, array $columns, array $options = []) : array
{
Expand Down Expand Up @@ -1436,7 +1436,7 @@ protected function _getCreateTableSQL(string $tableName, array $columns, array $
}
$query .= ')';

$sql[] = $query;
$sql = [$query];

if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $definition) {
Expand Down Expand Up @@ -1642,7 +1642,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table)
*
* This method returns an array of SQL statements, since some platforms need several statements.
*
* @return string[]
* @return array<int, string>
*
* @throws DBALException If not supported on this platform.
*/
Expand Down Expand Up @@ -1791,7 +1791,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) : array
$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 @@ -597,7 +597,7 @@ public function getAlterTableSQL(TableDiff $diff) : array

$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 @@ -512,7 +512,7 @@ public function getAlterTableSQL(TableDiff $diff) : array
$queryParts = [];
$newName = $diff->getNewName();

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

Expand Down Expand Up @@ -817,7 +817,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
4 changes: 2 additions & 2 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public function getDropViewSQL(string $name) : string
}

/**
* @return string[]
* @return array<int, string>
*/
public function getCreateAutoincrementSql(string $name, string $table, int $start = 1) : array
{
Expand Down Expand Up @@ -854,7 +854,7 @@ public function getAlterTableSQL(TableDiff $diff) : array

$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 @@ -591,7 +591,7 @@ public function getAlterTableSQL(TableDiff $diff) : array

$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) : array

$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 @@ -574,7 +574,7 @@ public function getAlterTableSQL(TableDiff $diff) : array

$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 @@ -671,7 +671,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) : array
$sql = [];
$tableName = $diff->getNewName();

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

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

$newName = $diff->getNewName();

if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$newTable->getQuotedName($this),
Expand Down Expand Up @@ -980,7 +980,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
Loading