Unverified Commit f9dd6a3f authored by Jonathan H. Wage's avatar Jonathan H. Wage Committed by Sergei Morozov

Add proper types to Doctrine\DBAL\Schema namespace.

parent ab424a1d
# 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.
- 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.
......
......@@ -25,7 +25,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)
......@@ -74,7 +74,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
}
/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
{
......
......@@ -89,7 +89,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
}
/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
{
......
<?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
)
);
}
}
......@@ -28,7 +28,7 @@ class TableGeneratorSchemaVisitor implements Visitor
/**
* {@inheritdoc}
*/
public function acceptSchema(Schema $schema)
public function acceptSchema(Schema $schema) : void
{
$table = $schema->createTable($this->generatorTableName);
$table->addColumn('sequence_name', 'string');
......@@ -39,35 +39,35 @@ class TableGeneratorSchemaVisitor implements Visitor
/**
* {@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
{
}
}
......@@ -1274,7 +1274,7 @@ abstract class AbstractPlatform
* 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
*/
......@@ -1420,7 +1420,7 @@ abstract class AbstractPlatform
* @param mixed[][] $columns
* @param mixed[] $options
*
* @return string[]
* @return array<int, string>
*/
protected function _getCreateTableSQL(string $tableName, array $columns, array $options = []) : array
{
......@@ -1450,7 +1450,7 @@ abstract class AbstractPlatform
}
$query .= ')';
$sql[] = $query;
$sql = [$query];
if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $definition) {
......@@ -1656,7 +1656,7 @@ abstract class AbstractPlatform
*
* 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.
*/
......@@ -1805,7 +1805,7 @@ abstract class AbstractPlatform
$sql = [];
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$tableName = $newName->getQuotedName($this);
} else {
$tableName = $diff->getName($this)->getQuotedName($this);
......
......@@ -597,7 +597,7 @@ class DB2Platform extends AbstractPlatform
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'RENAME TABLE %s TO %s',
$diff->getName($this)->getQuotedName($this),
......
......@@ -510,7 +510,7 @@ SQL
$queryParts = [];
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this);
}
......@@ -815,7 +815,7 @@ SQL
$sql = [];
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$tableName = $newName->getQuotedName($this);
} else {
$tableName = $diff->getName($this)->getQuotedName($this);
......
......@@ -461,7 +461,7 @@ class OraclePlatform extends AbstractPlatform
}
/**
* @return string[]
* @return array<int, string>
*/
public function getCreateAutoincrementSql(string $name, string $table, int $start = 1) : array
{
......@@ -854,7 +854,7 @@ SQL
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this),
......
......@@ -591,7 +591,7 @@ SQL
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this),
......
......@@ -190,7 +190,7 @@ class SQLAnywherePlatform extends AbstractPlatform
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' .
$this->getAlterTableRenameTableClause($newName);
}
......
......@@ -579,7 +579,7 @@ SQL
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'";
/**
......
......@@ -684,7 +684,7 @@ class SqlitePlatform extends AbstractPlatform
$sql = [];
$tableName = $diff->getNewName();
if ($tableName === false) {
if ($tableName === null) {
$tableName = $diff->getName($this);
}
......@@ -911,7 +911,7 @@ class SqlitePlatform extends AbstractPlatform
$newName = $diff->getNewName();
if ($newName !== false) {
if ($newName !== null) {
$sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s',
$newTable->getQuotedName($this),
......@@ -993,7 +993,7 @@ class SqlitePlatform extends AbstractPlatform
}
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);
}
......
......@@ -39,12 +39,8 @@ abstract class AbstractAsset
/**
* Sets the name of this asset.
*
* @param string $name
*
* @return void
*/
protected function _setName($name)
protected function _setName(string $name) : void
{
if ($this->isIdentifierQuoted($name)) {
$this->_quoted = true;
......@@ -60,12 +56,8 @@ abstract class AbstractAsset
/**
* Is this asset in the default namespace?
*
* @param string $defaultNamespaceName
*
* @return bool
*/
public function isInDefaultNamespace($defaultNamespaceName)
public function isInDefaultNamespace(string $defaultNamespaceName) : bool
{
return $this->_namespace === $defaultNamespaceName || $this->_namespace === null;
}
......@@ -74,10 +66,8 @@ abstract class AbstractAsset
* Gets the namespace name of this asset.
*
* If NULL is returned this means the default namespace is used.
*
* @return string|null
*/
public function getNamespaceName()
public function getNamespaceName() : ?string
{
return $this->_namespace;
}
......@@ -85,12 +75,8 @@ abstract class AbstractAsset
/**
* The shortest name is stripped of the default namespace. All other
* namespaced elements are returned as full-qualified names.
*
* @param string|null $defaultNamespaceName
*
* @return string
*/
public function getShortestName($defaultNamespaceName)
public function getShortestName(?string $defaultNamespaceName) : string
{
$shortestName = $this->getName();
if ($this->_namespace === $defaultNamespaceName) {
......@@ -108,12 +94,8 @@ abstract class AbstractAsset
*
* Every non-namespaced element is prefixed with the default namespace
* name which is passed as argument to this method.
*
* @param string $defaultNamespaceName
*
* @return string
*/
public function getFullQualifiedName($defaultNamespaceName)
public function getFullQualifiedName(string $defaultNamespaceName) : string
{
$name = $this->getName();
if (! $this->_namespace) {
......@@ -125,44 +107,32 @@ abstract class AbstractAsset
/**
* Checks if this asset's name is quoted.
*
* @return bool
*/
public function isQuoted()
public function isQuoted() : bool
{
return $this->_quoted;
}
/**
* Checks if this identifier is quoted.
*
* @param string $identifier
*
* @return bool
*/
protected function isIdentifierQuoted($identifier)
protected function isIdentifierQuoted(string $identifier) : bool
{
return isset($identifier[0]) && ($identifier[0] === '`' || $identifier[0] === '"' || $identifier[0] === '[');
}
/**
* Trim quotes from the identifier.
*
* @param string $identifier
*
* @return string
*/
protected function trimQuotes($identifier)
protected function trimQuotes(string $identifier) : string
{
return str_replace(['`', '"', '[', ']'], '', $identifier);
}
/**
* Returns the name of this schema asset.
*
* @return string
*/
public function getName()
public function getName() : string
{
if ($this->_namespace) {
return $this->_namespace . '.' . $this->_name;
......@@ -174,10 +144,8 @@ abstract class AbstractAsset
/**
* Gets the quoted representation of this asset but only if it was defined with one. Otherwise
* return the plain unquoted value as inserted.
*
* @return string
*/
public function getQuotedName(AbstractPlatform $platform)
public function getQuotedName(AbstractPlatform $platform) : string
{
$keywords = $platform->getReservedKeywordsList();
$parts = explode('.', $this->getName());
......@@ -195,13 +163,9 @@ abstract class AbstractAsset
* however building idents automatically for foreign keys, composite keys or such can easily create
* very long names.
*
* @param string[] $columnNames
* @param string $prefix
* @param int $maxSize
*
* @return string
* @param array<int, string> $columnNames
*/
protected function _generateIdentifierName($columnNames, $prefix = '', $maxSize = 30)
protected function _generateIdentifierName(array $columnNames, string $prefix = '', int $maxSize = 30) : string
{
$hash = implode('', array_map(static function ($column) {
return dechex(crc32($column));
......
......@@ -10,12 +10,14 @@ use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs;
use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Exception\DatabaseRequired;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use Throwable;
use function array_filter;
use function array_intersect;
use function array_map;
use function array_shift;
use function array_values;
use function assert;
use function call_user_func_array;
......@@ -57,10 +59,8 @@ abstract class AbstractSchemaManager
/**
* Returns the associated platform.
*
* @return AbstractPlatform
*/
public function getDatabasePlatform()
public function getDatabasePlatform() : AbstractPlatform
{
return $this->_platform;
}
......@@ -97,9 +97,9 @@ abstract class AbstractSchemaManager
/**
* Lists the available databases for this connection.
*
* @return string[]
* @return array<int, string>
*/
public function listDatabases()
public function listDatabases() : array
{
$sql = $this->_platform->getListDatabasesSQL();
......@@ -111,9 +111,9 @@ abstract class AbstractSchemaManager
/**
* Returns a list of all namespaces in the current database.
*
* @return string[]
* @return array<int, string>
*/
public function listNamespaceNames()
public function listNamespaceNames() : array
{
$sql = $this->_platform->getListNamespacesSQL();
......@@ -125,15 +125,15 @@ abstract class AbstractSchemaManager
/**
* Lists the available sequences for this connection.
*
* @param string|null $database
*
* @return Sequence[]
* @return array<int, Sequence>
*/
public function listSequences($database = null)
public function listSequences(?string $database = null) : array
{
if ($database === null) {
$database = $this->_conn->getDatabase();
}
$database = $this->ensureDatabase(
$database ?? $this->_conn->getDatabase(),
__METHOD__
);
$sql = $this->_platform->getListSequencesSQL($database);
$sequences = $this->_conn->fetchAll($sql);
......@@ -151,16 +151,14 @@ abstract class AbstractSchemaManager
* of a table. Where a RDBMS specifies more details, these are held
* in the platformDetails array.
*
* @param string $table The name of the table.
* @param string|null $database
*
* @return Column[]
* @return array<string, Column>
*/
public function listTableColumns($table, $database = null)
public function listTableColumns(string $table, ?string $database = null) : array
{
if (! $database) {
$database = $this->_conn->getDatabase();
}
$database = $this->ensureDatabase(
$database ?? $this->_conn->getDatabase(),
__METHOD__
);
$sql = $this->_platform->getListTableColumnsSQL($table, $database);
......@@ -174,11 +172,9 @@ abstract class AbstractSchemaManager
*
* Keys of the portable indexes list are all lower-cased.
*
* @param string $table The name of the table.
*
* @return Index[]
* @return array<string, Index>
*/
public function listTableIndexes($table)
public function listTableIndexes(string $table) : array
{
$sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
......@@ -190,25 +186,26 @@ abstract class AbstractSchemaManager
/**
* Returns true if all the given tables exist.
*
* The usage of a string $tableNames is deprecated. Pass a one-element array instead.
*
* @param string|string[] $tableNames
*
* @return bool
* @param array<int, string> $tableNames
*/
public function tablesExist($tableNames)
public function tablesExist(array $tableNames) : bool
{
$tableNames = array_map('strtolower', (array) $tableNames);
$tableNames = array_map('strtolower', $tableNames);
return count($tableNames) === count(array_intersect($tableNames, array_map('strtolower', $this->listTableNames())));
}
public function tableExists(string $tableName) : bool
{
return $this->tablesExist([$tableName]);
}
/**
* Returns a list of all tables in the current database.
*
* @return string[]
* @return array<int, string>
*/
public function listTableNames()
public function listTableNames() : array
{
$sql = $this->_platform->getListTablesSQL();
......@@ -222,11 +219,11 @@ abstract class AbstractSchemaManager
* Filters asset names if they are configured to return only a subset of all
* the found elements.
*
* @param mixed[] $assetNames
* @param array<int, mixed> $assetNames
*
* @return mixed[]
* @return array<int, mixed>
*/
protected function filterAssetNames($assetNames)
protected function filterAssetNames(array $assetNames)
{
$filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter();
if (! $filter) {
......@@ -239,9 +236,9 @@ abstract class AbstractSchemaManager
/**
* Lists the tables for this connection.
*
* @return Table[]
* @return array<int, Table>
*/
public function listTables()
public function listTables() : array
{
$tableNames = $this->listTableNames();
......@@ -253,12 +250,7 @@ abstract class AbstractSchemaManager
return $tables;
}
/**
* @param string $tableName
*
* @return Table
*/
public function listTableDetails($tableName)
public function listTableDetails(string $tableName) : Table
{
$columns = $this->listTableColumns($tableName);
$foreignKeys = [];
......@@ -275,13 +267,17 @@ abstract class AbstractSchemaManager
/**
* Lists the views this connection has.
*
* @return View[]
* @return array<string, View>
*/
public function listViews()
public function listViews() : array
{
$database = $this->_conn->getDatabase();
$sql = $this->_platform->getListViewsSQL($database);
$views = $this->_conn->fetchAll($sql);
$database = $this->ensureDatabase(
$this->_conn->getDatabase(),
__METHOD__
);
$sql = $this->_platform->getListViewsSQL($database);
$views = $this->_conn->fetchAll($sql);
return $this->_getPortableViewsList($views);
}
......@@ -289,12 +285,9 @@ abstract class AbstractSchemaManager
/**
* Lists the foreign keys for the given table.
*
* @param string $table The name of the table.
* @param string|null $database
*
* @return ForeignKeyConstraint[]
* @return array<int|string, ForeignKeyConstraint>
*/
public function listTableForeignKeys($table, $database = null)
public function listTableForeignKeys(string $table, ?string $database = null) : array
{
if ($database === null) {
$database = $this->_conn->getDatabase();
......@@ -311,24 +304,16 @@ abstract class AbstractSchemaManager
* Drops a database.
*
* NOTE: You can not drop the database this SchemaManager is currently connected to.
*
* @param string $database The name of the database to drop.
*
* @return void
*/
public function dropDatabase($database)
public function dropDatabase(string $database) : void
{
$this->_execSql($this->_platform->getDropDatabaseSQL($database));
}
/**
* Drops the given table.
*
* @param string $tableName The name of the table to drop.
*
* @return void
*/
public function dropTable($tableName)
public function dropTable(string $tableName) : void
{
$this->_execSql($this->_platform->getDropTableSQL($tableName));
}
......@@ -338,10 +323,8 @@ abstract class AbstractSchemaManager
*
* @param Index|string $index The name of the index.
* @param Table|string $table The name of the table.
*
* @return void
*/
public function dropIndex($index, $table)
public function dropIndex($index, $table) : void
{
if ($index instanceof Index) {
$index = $index->getQuotedName($this->_platform);
......@@ -354,10 +337,8 @@ abstract class AbstractSchemaManager
* Drops the constraint from the given table.
*
* @param Table|string $table The name of the table.
*
* @return void
*/
public function dropConstraint(Constraint $constraint, $table)
public function dropConstraint(Constraint $constraint, $table) : void
{
$this->_execSql($this->_platform->getDropConstraintSQL($constraint, $table));
}
......@@ -367,34 +348,24 @@ abstract class AbstractSchemaManager
*
* @param ForeignKeyConstraint|string $foreignKey The name of the foreign key.
* @param Table|string $table The name of the table with the foreign key.
*
* @return void
*/
public function dropForeignKey($foreignKey, $table)
public function dropForeignKey($foreignKey, $table) : void
{
$this->_execSql($this->_platform->getDropForeignKeySQL($foreignKey, $table));
}
/**
* Drops a sequence with a given name.
*
* @param string $name The name of the sequence to drop.
*
* @return void
*/
public function dropSequence($name)
public function dropSequence(string $name) : void
{
$this->_execSql($this->_platform->getDropSequenceSQL($name));
}
/**
* Drops a view.
*
* @param string $name The name of the view.
*
* @return void
*/
public function dropView($name)
public function dropView(string $name) : void
{
$this->_execSql($this->_platform->getDropViewSQL($name));
}
......@@ -403,22 +374,16 @@ abstract class AbstractSchemaManager
/**
* Creates a new database.
*
* @param string $database The name of the database to create.
*
* @return void
*/
public function createDatabase($database)
public function createDatabase(string $database) : void
{
$this->_execSql($this->_platform->getCreateDatabaseSQL($database));
}
/**
* Creates a new table.
*
* @return void
*/
public function createTable(Table $table)
public function createTable(Table $table) : void
{
$createFlags = AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS;
$this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags));
......@@ -427,13 +392,9 @@ abstract class AbstractSchemaManager
/**
* Creates a new sequence.
*
* @param Sequence $sequence
*
* @return void
*
* @throws ConnectionException If something fails at database level.
*/
public function createSequence($sequence)
public function createSequence(Sequence $sequence) : void
{
$this->_execSql($this->_platform->getCreateSequenceSQL($sequence));
}
......@@ -442,10 +403,8 @@ abstract class AbstractSchemaManager
* Creates a constraint on a table.
*
* @param Table|string $table
*
* @return void
*/
public function createConstraint(Constraint $constraint, $table)
public function createConstraint(Constraint $constraint, $table) : void
{
$this->_execSql($this->_platform->getCreateConstraintSQL($constraint, $table));
}
......@@ -454,10 +413,8 @@ abstract class AbstractSchemaManager
* Creates a new index on a table.
*
* @param Table|string $table The name of the table on which the index is to be created.
*
* @return void
*/
public function createIndex(Index $index, $table)
public function createIndex(Index $index, $table) : void
{
$this->_execSql($this->_platform->getCreateIndexSQL($index, $table));
}
......@@ -467,20 +424,16 @@ abstract class AbstractSchemaManager
*
* @param ForeignKeyConstraint $foreignKey The ForeignKey instance.
* @param Table|string $table The name of the table on which the foreign key is to be created.
*
* @return void
*/
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) : void
{
$this->_execSql($this->_platform->getCreateForeignKeySQL($foreignKey, $table));
}
/**
* Creates a new view.
*
* @return void
*/
public function createView(View $view)
public function createView(View $view) : void
{
$this->_execSql($this->_platform->getCreateViewSQL($view->getQuotedName($this->_platform), $view->getSql()));
}
......@@ -494,10 +447,8 @@ abstract class AbstractSchemaManager
* @see createConstraint()
*
* @param Table|string $table
*
* @return void
*/
public function dropAndCreateConstraint(Constraint $constraint, $table)
public function dropAndCreateConstraint(Constraint $constraint, $table) : void
{
$this->tryMethod('dropConstraint', $constraint, $table);
$this->createConstraint($constraint, $table);
......@@ -507,10 +458,8 @@ abstract class AbstractSchemaManager
* Drops and creates a new index on a table.
*
* @param Table|string $table The name of the table on which the index is to be created.
*
* @return void
*/
public function dropAndCreateIndex(Index $index, $table)
public function dropAndCreateIndex(Index $index, $table) : void
{
$this->tryMethod('dropIndex', $index->getQuotedName($this->_platform), $table);
$this->createIndex($index, $table);
......@@ -521,10 +470,8 @@ abstract class AbstractSchemaManager
*
* @param ForeignKeyConstraint $foreignKey An associative array that defines properties of the foreign key to be created.
* @param Table|string $table The name of the table on which the foreign key is to be created.
*
* @return void
*/
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) : void
{
$this->tryMethod('dropForeignKey', $foreignKey, $table);
$this->createForeignKey($foreignKey, $table);
......@@ -533,11 +480,9 @@ abstract class AbstractSchemaManager
/**
* Drops and create a new sequence.
*
* @return void
*
* @throws ConnectionException If something fails at database level.
*/
public function dropAndCreateSequence(Sequence $sequence)
public function dropAndCreateSequence(Sequence $sequence) : void
{
$this->tryMethod('dropSequence', $sequence->getQuotedName($this->_platform));
$this->createSequence($sequence);
......@@ -545,10 +490,8 @@ abstract class AbstractSchemaManager
/**
* Drops and creates a new table.
*
* @return void
*/
public function dropAndCreateTable(Table $table)
public function dropAndCreateTable(Table $table) : void
{
$this->tryMethod('dropTable', $table->getQuotedName($this->_platform));
$this->createTable($table);
......@@ -556,12 +499,8 @@ abstract class AbstractSchemaManager
/**
* Drops and creates a new database.
*
* @param string $database The name of the database to create.
*
* @return void
*/
public function dropAndCreateDatabase($database)
public function dropAndCreateDatabase(string $database) : void
{
$this->tryMethod('dropDatabase', $database);
$this->createDatabase($database);
......@@ -569,10 +508,8 @@ abstract class AbstractSchemaManager
/**
* Drops and creates a new view.
*
* @return void
*/
public function dropAndCreateView(View $view)
public function dropAndCreateView(View $view) : void
{
$this->tryMethod('dropView', $view->getQuotedName($this->_platform));
$this->createView($view);
......@@ -582,10 +519,8 @@ abstract class AbstractSchemaManager
/**
* Alters an existing tables schema.
*
* @return void
*/
public function alterTable(TableDiff $tableDiff)
public function alterTable(TableDiff $tableDiff) : void
{
$queries = $this->_platform->getAlterTableSQL($tableDiff);
......@@ -600,13 +535,8 @@ abstract class AbstractSchemaManager
/**
* Renames a given table to another name.
*
* @param string $name The current name of the table.
* @param string $newName The new name of the table.
*
* @return void
*/
public function renameTable($name, $newName)
public function renameTable(string $name, string $newName) : void
{
$tableDiff = new TableDiff($name);
$tableDiff->newName = $newName;
......@@ -619,11 +549,11 @@ abstract class AbstractSchemaManager
*/
/**
* @param mixed[] $databases
* @param array<int, mixed> $databases
*
* @return string[]
* @return array<int, string>
*/
protected function _getPortableDatabasesList($databases)
protected function _getPortableDatabasesList(array $databases) : array
{
$list = [];
foreach ($databases as $value) {
......@@ -642,11 +572,11 @@ abstract class AbstractSchemaManager
/**
* Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition.
*
* @param mixed[][] $namespaces The list of namespace names in the native DBMS data definition.
* @param array<int, array<int, mixed>> $namespaces The list of namespace names in the native DBMS data definition.
*
* @return string[]
* @return array<int, string>
*/
protected function getPortableNamespacesList(array $namespaces)
protected function getPortableNamespacesList(array $namespaces) : array
{
$namespacesList = [];
......@@ -658,68 +588,29 @@ abstract class AbstractSchemaManager
}
/**
* @param mixed $database
*
* @return mixed
* @param array<string, string> $database
*/
protected function _getPortableDatabaseDefinition($database)
protected function _getPortableDatabaseDefinition(array $database) : string
{
return $database;
return array_shift($database);
}
/**
* Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition.
*
* @param mixed[] $namespace The native DBMS namespace definition.
*
* @return mixed
*/
protected function getPortableNamespaceDefinition(array $namespace)
{
return $namespace;
}
/**
* @deprecated
*
* @param mixed[][] $functions
*
* @return mixed[][]
*/
protected function _getPortableFunctionsList($functions)
{
$list = [];
foreach ($functions as $value) {
$value = $this->_getPortableFunctionDefinition($value);
if (! $value) {
continue;
}
$list[] = $value;
}
return $list;
}
/**
* @deprecated
*
* @param mixed[] $function
*
* @return mixed
* @param array<string|int, mixed> $namespace The native DBMS namespace definition.
*/
protected function _getPortableFunctionDefinition($function)
protected function getPortableNamespaceDefinition(array $namespace) : string
{
return $function;
return array_shift($namespace);
}
/**
* @param mixed[][] $triggers
* @param array<int, array<int, mixed>> $triggers
*
* @return mixed[][]
* @return array<int, string>
*/
protected function _getPortableTriggersList($triggers)
protected function _getPortableTriggersList(array $triggers)
{
$list = [];
foreach ($triggers as $value) {
......@@ -736,21 +627,19 @@ abstract class AbstractSchemaManager
}
/**
* @param mixed[] $trigger
*
* @return mixed
* @param array<string|int, mixed> $trigger
*/
protected function _getPortableTriggerDefinition($trigger)
protected function _getPortableTriggerDefinition(array $trigger) : string
{
return $trigger;
return array_shift($trigger);
}
/**
* @param mixed[][] $sequences
* @param array<int, array<string, mixed>> $sequences
*
* @return Sequence[]
* @return array<int, Sequence>
*/
protected function _getPortableSequencesList($sequences)
protected function _getPortableSequencesList(array $sequences) : array
{
$list = [];
......@@ -762,13 +651,11 @@ abstract class AbstractSchemaManager
}
/**
* @param mixed[] $sequence
*
* @return Sequence
* @param array<string, mixed> $sequence
*
* @throws DBALException
*/
protected function _getPortableSequenceDefinition($sequence)
protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{
throw NotSupported::new('Sequences');
}
......@@ -778,13 +665,11 @@ abstract class AbstractSchemaManager
*
* The name of the created column instance however is kept in its case.
*
* @param string $table The name of the table.
* @param string $database
* @param mixed[][] $tableColumns
* @param array<int, array<string, mixed>> $tableColumns
*
* @return Column[]
* @return array<string, Column>
*/
protected function _getPortableTableColumnList($table, $database, $tableColumns)
protected function _getPortableTableColumnList(string $table, string $database, array $tableColumns) : array
{
$eventManager = $this->_platform->getEventManager();
......@@ -819,18 +704,16 @@ abstract class AbstractSchemaManager
/**
* Gets Table Column Definition.
*
* @param mixed[] $tableColumn
*
* @return Column
* @param array<string, mixed> $tableColumn
*/
abstract protected function _getPortableTableColumnDefinition($tableColumn);
abstract protected function _getPortableTableColumnDefinition(array $tableColumn) : Column;
/**
* Aggregates and groups the index results according to the required data result.
*
* @param mixed[][] $tableIndexRows
* @param array<int, array<string, mixed>> $tableIndexRows
*
* @return Index[]
* @return array<string, Index>
*/
protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array
{
......@@ -895,11 +778,11 @@ abstract class AbstractSchemaManager
}
/**
* @param mixed[][] $tables
* @param array<int, array<string, mixed>> $tables
*
* @return string[]
* @return array<int, string>
*/
protected function _getPortableTablesList($tables)
protected function _getPortableTablesList(array $tables) : array
{
$list = [];
foreach ($tables as $value) {
......@@ -916,21 +799,19 @@ abstract class AbstractSchemaManager
}
/**
* @param mixed $table
*
* @return string
* @param array<string, string> $table
*/
protected function _getPortableTableDefinition($table)
protected function _getPortableTableDefinition(array $table) : string
{
return $table;
return array_shift($table);
}
/**
* @param mixed[][] $users
* @param array<int, array<string, mixed>> $users
*
* @return string[][]
* @return array<int, array<string, mixed>>
*/
protected function _getPortableUsersList($users)
protected function _getPortableUsersList(array $users) : array
{
$list = [];
foreach ($users as $value) {
......@@ -947,53 +828,46 @@ abstract class AbstractSchemaManager
}
/**
* @param string[] $user
* @param array<string, mixed> $user
*
* @return string[]
* @return array<string, mixed>
*/
protected function _getPortableUserDefinition($user)
protected function _getPortableUserDefinition(array $user) : array
{
return $user;
}
/**
* @param mixed[][] $views
* @param array<int, array<string, mixed>> $views
*
* @return View[]
* @return array<string, View>
*/
protected function _getPortableViewsList($views)
protected function _getPortableViewsList(array $views) : array
{
$list = [];
foreach ($views as $value) {
$view = $this->_getPortableViewDefinition($value);
if (! $view) {
continue;
}
$viewName = strtolower($view->getQuotedName($this->_platform));
$list[$viewName] = $view;
$view = $this->_getPortableViewDefinition($value);
$name = strtolower($view->getQuotedName($this->_platform));
$list[$name] = $view;
}
return $list;
}
/**
* @param mixed[] $view
*
* @return View|false
* @param array<string, mixed> $view
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : View
{
return false;
throw NotSupported::new('Views');
}
/**
* @param mixed[][] $tableForeignKeys
* @param array<int|string, array<string, mixed>> $tableForeignKeys
*
* @return ForeignKeyConstraint[]
* @return array<int, ForeignKeyConstraint>
*/
protected function _getPortableTableForeignKeysList($tableForeignKeys)
protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{
$list = [];
......@@ -1005,21 +879,17 @@ abstract class AbstractSchemaManager
}
/**
* @param mixed $tableForeignKey
*
* @return ForeignKeyConstraint
* @param array<string, mixed> $tableForeignKey
*/
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{
return $tableForeignKey;
throw NotSupported::new('ForeignKey');
}
/**
* @param string[]|string $sql
*
* @return void
* @param array<int, string>|string $sql
*/
protected function _execSql($sql)
protected function _execSql($sql) : void
{
foreach ((array) $sql as $query) {
$this->_conn->executeUpdate($query);
......@@ -1028,10 +898,8 @@ abstract class AbstractSchemaManager
/**
* Creates a schema instance for the current database.
*
* @return Schema
*/
public function createSchema()
public function createSchema() : Schema
{
$namespaces = [];
......@@ -1052,10 +920,8 @@ abstract class AbstractSchemaManager
/**
* Creates the configuration for this schema.
*
* @return SchemaConfig
*/
public function createSchemaConfig()
public function createSchemaConfig() : SchemaConfig
{
$schemaConfig = new SchemaConfig();
$schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength());
......@@ -1087,9 +953,9 @@ abstract class AbstractSchemaManager
* For databases that don't support subschema/namespaces this method
* returns the name of the currently connected database.
*
* @return string[]
* @return array<int, string>
*/
public function getSchemaSearchPaths()
public function getSchemaSearchPaths() : array
{
return [$this->_conn->getDatabase()];
}
......@@ -1110,4 +976,16 @@ abstract class AbstractSchemaManager
return $match[2];
}
/**
* @throws DatabaseRequired
*/
private function ensureDatabase(?string $database, string $methodName) : string
{
if ($database === null) {
throw DatabaseRequired::new($methodName);
}
return $database;
}
}
......@@ -43,7 +43,7 @@ class Column extends AbstractAsset
/** @var bool */
protected $_autoincrement = false;
/** @var mixed[] */
/** @var array<string, mixed> */
protected $_platformOptions = [];
/** @var string|null */
......@@ -52,13 +52,13 @@ class Column extends AbstractAsset
/** @var string|null */
protected $_comment;
/** @var mixed[] */
/** @var array<string, mixed> */
protected $_customSchemaOptions = [];
/**
* Creates a new Column.
*
* @param mixed[] $options
* @param array<string, mixed> $options
*/
public function __construct(string $name, Type $type, array $options = [])
{
......@@ -68,7 +68,7 @@ class Column extends AbstractAsset
}
/**
* @param mixed[] $options
* @param array<string, mixed> $options
*/
public function setOptions(array $options) : self
{
......@@ -154,7 +154,7 @@ class Column extends AbstractAsset
}
/**
* @param mixed[] $platformOptions
* @param array<string, mixed> $platformOptions
*/
public function setPlatformOptions(array $platformOptions) : self
{
......@@ -224,7 +224,7 @@ class Column extends AbstractAsset
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getPlatformOptions() : array
{
......@@ -297,7 +297,7 @@ class Column extends AbstractAsset
}
/**
* @param mixed[] $customSchemaOptions
* @param array<string, mixed> $customSchemaOptions
*/
public function setCustomSchemaOptions(array $customSchemaOptions) : self
{
......@@ -307,7 +307,7 @@ class Column extends AbstractAsset
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getCustomSchemaOptions() : array
{
......@@ -315,7 +315,7 @@ class Column extends AbstractAsset
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function toArray() : array
{
......
......@@ -17,17 +17,16 @@ class ColumnDiff
/** @var Column */
public $column;
/** @var string[] */
/** @var array<int, string> */
public $changedProperties = [];
/** @var Column|null */
public $fromColumn;
/**
* @param string $oldColumnName
* @param string[] $changedProperties
* @param array<string> $changedProperties
*/
public function __construct($oldColumnName, Column $column, array $changedProperties = [], ?Column $fromColumn = null)
public function __construct(string $oldColumnName, Column $column, array $changedProperties = [], ?Column $fromColumn = null)
{
$this->oldColumnName = $oldColumnName;
$this->column = $column;
......@@ -35,20 +34,12 @@ class ColumnDiff
$this->fromColumn = $fromColumn;
}
/**
* @param string $propertyName
*
* @return bool
*/
public function hasChanged($propertyName)
public function hasChanged(string $propertyName) : bool
{
return in_array($propertyName, $this->changedProperties);
}
/**
* @return Identifier
*/
public function getOldColumnName()
public function getOldColumnName() : Identifier
{
$quote = $this->fromColumn && $this->fromColumn->isQuoted();
......
......@@ -21,10 +21,7 @@ use function strtolower;
*/
class Comparator
{
/**
* @return SchemaDiff
*/
public static function compareSchemas(Schema $fromSchema, Schema $toSchema)
public static function compareSchemas(Schema $fromSchema, Schema $toSchema) : SchemaDiff
{
$c = new self();
......@@ -37,10 +34,8 @@ class Comparator
* The returned differences are returned in such a way that they contain the
* operations to change the schema stored in $fromSchema to the schema that is
* stored in $toSchema.
*
* @return SchemaDiff
*/
public function compare(Schema $fromSchema, Schema $toSchema)
public function compare(Schema $fromSchema, Schema $toSchema) : SchemaDiff
{
$diff = new SchemaDiff();
$diff->fromSchema = $fromSchema;
......@@ -69,7 +64,7 @@ class Comparator
$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;
}
}
......@@ -152,13 +147,7 @@ class Comparator
return $diff;
}
/**
* @param Schema $schema
* @param Sequence $sequence
*
* @return bool
*/
private function isAutoIncrementSequenceInSchema($schema, $sequence)
private function isAutoIncrementSequenceInSchema(Schema $schema, Sequence $sequence) : bool
{
foreach ($schema->getTables() as $table) {
if ($sequence->isAutoIncrementsFor($table)) {
......@@ -169,10 +158,7 @@ class Comparator
return false;
}
/**
* @return bool
*/
public function diffSequence(Sequence $sequence1, Sequence $sequence2)
public function diffSequence(Sequence $sequence1, Sequence $sequence2) : bool
{
if ($sequence1->getAllocationSize() !== $sequence2->getAllocationSize()) {
return true;
......@@ -185,10 +171,8 @@ class Comparator
* 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());
......@@ -294,16 +278,14 @@ class Comparator
$changes++;
}
return $changes ? $tableDifferences : false;
return $changes ? $tableDifferences : null;
}
/**
* Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
* however ambiguities between different possibilities should not lead to renaming at all.
*
* @return void
*/
private function detectColumnRenamings(TableDiff $tableDifferences)
private function detectColumnRenamings(TableDiff $tableDifferences) : void
{
$renameCandidates = [];
foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) {
......@@ -340,10 +322,8 @@ class Comparator
/**
* Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop
* however ambiguities between different possibilities should not lead to renaming at all.
*
* @return void
*/
private function detectIndexRenamings(TableDiff $tableDifferences)
private function detectIndexRenamings(TableDiff $tableDifferences) : void
{
$renameCandidates = [];
......@@ -384,10 +364,7 @@ class Comparator
}
}
/**
* @return bool
*/
public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2)
public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2) : bool
{
if (array_map('strtolower', $key1->getUnquotedLocalColumns()) !== array_map('strtolower', $key2->getUnquotedLocalColumns())) {
return true;
......@@ -414,9 +391,9 @@ class Comparator
* If there are differences this method returns $field2, otherwise the
* boolean false.
*
* @return string[]
* @return array<int, string>
*/
public function diffColumn(Column $column1, Column $column2)
public function diffColumn(Column $column1, Column $column2) : array
{
$properties1 = $column1->toArray();
$properties2 = $column2->toArray();
......@@ -502,10 +479,8 @@ class Comparator
*
* Compares $index1 with $index2 and returns $index2 if there are any
* differences or false in case there are no differences.
*
* @return bool
*/
public function diffIndex(Index $index1, Index $index2)
public function diffIndex(Index $index1, Index $index2) : bool
{
return ! ($index1->isFullfilledBy($index2) && $index2->isFullfilledBy($index1));
}
......
......@@ -11,23 +11,17 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
*/
interface Constraint
{
/**
* @return string
*/
public function getName();
public function getName() : string;
/**
* @return string
*/
public function getQuotedName(AbstractPlatform $platform);
public function getQuotedName(AbstractPlatform $platform) : string;
/**
* Returns the names of the referencing table columns
* the constraint is associated with.
*
* @return string[]
* @return array<int, string>
*/
public function getColumns();
public function getColumns() : array;
/**
* Returns the quoted representation of the column names
......@@ -39,7 +33,7 @@ interface Constraint
*
* @param AbstractPlatform $platform The platform to use for quotation.
*
* @return string[]
* @return array<int, string>
*/
public function getQuotedColumns(AbstractPlatform $platform);
public function getQuotedColumns(AbstractPlatform $platform) : array;
}
......@@ -43,7 +43,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
......@@ -105,7 +105,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTablesList($tables)
protected function _getPortableTablesList(array $tables) : array
{
$tableNames = [];
foreach ($tables as $tableRow) {
......@@ -132,7 +132,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{
return new ForeignKeyConstraint(
$tableForeignKey['local_columns'],
......@@ -146,7 +146,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeysList($tableForeignKeys)
protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{
$foreignKeys = [];
......@@ -176,7 +176,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/**
* {@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
......@@ -191,7 +191,7 @@ class DB2SchemaManager extends AbstractSchemaManager
return new View($view['name'], $sql);
}
public function listTableDetails($tableName) : Table
public function listTableDetails(string $tableName) : Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -27,9 +27,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Asset identifier instances of the referencing table column names the foreign key constraint is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
* @var array<string, Identifier>
*/
protected $_localColumnNames;
......@@ -42,27 +41,26 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Asset identifier instances of the referenced table column names the foreign key constraint is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
* @var array<string, Identifier>
*/
protected $_foreignColumnNames;
/**
* Options associated with the foreign key constraint.
*
* @var mixed[]
* @var array<string, mixed>
*/
protected $_options;
/**
* Initializes the foreign key constraint.
*
* @param string[] $localColumnNames Names of the referencing table columns.
* @param Table|string $foreignTableName Referenced table.
* @param string[] $foreignColumnNames Names of the referenced table columns.
* @param string|null $name Name of the foreign key constraint.
* @param mixed[] $options Options associated with the foreign key constraint.
* @param array<int, string> $localColumnNames Names of the referencing table columns.
* @param Table|string $foreignTableName Referenced table.
* @param array<int, string> $foreignColumnNames Names of the referenced table columns.
* @param string|null $name Name of the foreign key constraint.
* @param array<string, mixed> $options Options associated with the foreign key constraint.
*/
public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = [])
{
......@@ -83,9 +81,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
}
/**
* @param string[] $names
* @param array<int, string> $names
*
* @return Identifier[]
* @return array<string, Identifier>
*/
private function createIdentifierMap(array $names) : array
{
......@@ -101,10 +99,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns the name of the referencing table
* the foreign key constraint is associated with.
*
* @return string
*/
public function getLocalTableName()
public function getLocalTableName() : string
{
return $this->_localTable->getName();
}
......@@ -112,20 +108,13 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Sets the Table instance of the referencing table
* the foreign key constraint is associated with.
*
* @param Table $table Instance of the referencing table.
*
* @return void
*/
public function setLocalTable(Table $table)
public function setLocalTable(Table $table) : void
{
$this->_localTable = $table;
}
/**
* @return Table
*/
public function getLocalTable()
public function getLocalTable() : Table
{
return $this->_localTable;
}
......@@ -134,9 +123,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
* Returns the names of the referencing table columns
* the foreign key constraint is associated with.
*
* @return string[]
* @return array<int, string>
*/
public function getLocalColumns()
public function getLocalColumns() : array
{
return array_keys($this->_localColumnNames);
}
......@@ -151,9 +140,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*
* @param AbstractPlatform $platform The platform to use for quotation.
*
* @return string[]
* @return array<int, string>
*/
public function getQuotedLocalColumns(AbstractPlatform $platform)
public function getQuotedLocalColumns(AbstractPlatform $platform) : array
{
$columns = [];
......@@ -167,9 +156,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns unquoted representation of local table column names for comparison with other FK
*
* @return string[]
* @return array<int, string>
*/
public function getUnquotedLocalColumns()
public function getUnquotedLocalColumns() : array
{
return array_map([$this, 'trimQuotes'], $this->getLocalColumns());
}
......@@ -177,9 +166,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns unquoted representation of foreign table column names for comparison with other FK
*
* @return string[]
* @return array<int, string>
*/
public function getUnquotedForeignColumns()
public function getUnquotedForeignColumns() : array
{
return array_map([$this, 'trimQuotes'], $this->getForeignColumns());
}
......@@ -189,7 +178,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*
* @see getLocalColumns
*/
public function getColumns()
public function getColumns() : array
{
return $this->getLocalColumns();
}
......@@ -206,9 +195,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*
* @param AbstractPlatform $platform The platform to use for quotation.
*
* @return string[]
* @return array<int, string>
*/
public function getQuotedColumns(AbstractPlatform $platform)
public function getQuotedColumns(AbstractPlatform $platform) : array
{
return $this->getQuotedLocalColumns($platform);
}
......@@ -216,20 +205,16 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns the name of the referenced table
* the foreign key constraint is associated with.
*
* @return string
*/
public function getForeignTableName()
public function getForeignTableName() : string
{
return $this->_foreignTableName->getName();
}
/**
* Returns the non-schema qualified foreign table name.
*
* @return string
*/
public function getUnqualifiedForeignTableName()
public function getUnqualifiedForeignTableName() : string
{
$name = $this->_foreignTableName->getName();
$position = strrpos($name, '.');
......@@ -250,10 +235,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
* Otherwise the plain unquoted value as inserted is returned.
*
* @param AbstractPlatform $platform The platform to use for quotation.
*
* @return string
*/
public function getQuotedForeignTableName(AbstractPlatform $platform)
public function getQuotedForeignTableName(AbstractPlatform $platform) : string
{
return $this->_foreignTableName->getQuotedName($platform);
}
......@@ -262,9 +245,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
* Returns the names of the referenced table columns
* the foreign key constraint is associated with.
*
* @return string[]
* @return array<int, string>
*/
public function getForeignColumns()
public function getForeignColumns() : array
{
return array_keys($this->_foreignColumnNames);
}
......@@ -279,9 +262,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
*
* @param AbstractPlatform $platform The platform to use for quotation.
*
* @return string[]
* @return array<int, string>
*/
public function getQuotedForeignColumns(AbstractPlatform $platform)
public function getQuotedForeignColumns(AbstractPlatform $platform) : array
{
$columns = [];
......@@ -295,12 +278,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns whether or not a given option
* is associated with the foreign key constraint.
*
* @param string $name Name of the option to check.
*
* @return bool
*/
public function hasOption($name)
public function hasOption(string $name) : bool
{
return isset($this->_options[$name]);
}
......@@ -308,11 +287,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns an option associated with the foreign key constraint.
*
* @param string $name Name of the option the foreign key constraint is associated with.
*
* @return mixed
*/
public function getOption($name)
public function getOption(string $name)
{
return $this->_options[$name];
}
......@@ -320,9 +297,9 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns the options associated with the foreign key constraint.
*
* @return mixed[]
* @return array<string, mixed>
*/
public function getOptions()
public function getOptions() : array
{
return $this->_options;
}
......@@ -330,10 +307,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns the referential action for UPDATE operations
* on the referenced table the foreign key constraint is associated with.
*
* @return string|null
*/
public function onUpdate()
public function onUpdate() : ?string
{
return $this->onEvent('onUpdate');
}
......@@ -341,10 +316,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
/**
* Returns the referential action for DELETE operations
* on the referenced table the foreign key constraint is associated with.
*
* @return string|null
*/
public function onDelete()
public function onDelete() : ?string
{
return $this->onEvent('onDelete');
}
......@@ -354,10 +327,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
* on the referenced table the foreign key constraint is associated with.
*
* @param string $event Name of the database operation/event to return the referential action for.
*
* @return string|null
*/
private function onEvent($event)
private function onEvent(string $event) : ?string
{
if (isset($this->_options[$event])) {
$onEvent = strtoupper($this->_options[$event]);
......@@ -367,7 +338,7 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
}
}
return false;
return null;
}
/**
......@@ -377,10 +348,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
* matches one of the given index's columns, `false` otherwise.
*
* @param Index $index The index to be checked against.
*
* @return bool
*/
public function intersectsIndexColumns(Index $index)
public function intersectsIndexColumns(Index $index) : bool
{
foreach ($index->getColumns() as $indexColumn) {
foreach ($this->_localColumnNames as $localColumn) {
......
......@@ -16,7 +16,7 @@ class Identifier extends AbstractAsset
* @param string $identifier Identifier name to wrap.
* @param bool $quote Whether to force quoting the given identifier.
*/
public function __construct($identifier, $quote = false)
public function __construct(string $identifier, bool $quote = false)
{
$this->_setName($identifier);
......
......@@ -5,23 +5,20 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use InvalidArgumentException;
use function array_filter;
use function array_keys;
use function array_map;
use function array_search;
use function array_shift;
use function count;
use function is_string;
use function strtolower;
class Index extends AbstractAsset implements Constraint
{
/**
* Asset identifier instances of the column names the index is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
* @var array<string, Identifier>
*/
protected $_columns = [];
......@@ -33,9 +30,8 @@ class Index extends AbstractAsset implements Constraint
/**
* Platform specific flags for indexes.
* array($flagName => true)
*
* @var true[]
* @var array<string, true>
*/
protected $_flags = [];
......@@ -43,19 +39,16 @@ class Index extends AbstractAsset implements Constraint
* Platform specific options
*
* @todo $_flags should eventually be refactored into options
* @var mixed[]
* @var array<string, mixed>
*/
private $options = [];
/**
* @param string $indexName
* @param string[] $columns
* @param bool $isUnique
* @param bool $isPrimary
* @param string[] $flags
* @param mixed[] $options
* @param array<int, string> $columns
* @param array<int, string> $flags
* @param array<string, mixed> $options
*/
public function __construct($indexName, array $columns, $isUnique = false, $isPrimary = false, array $flags = [], array $options = [])
public function __construct(?string $indexName, array $columns, bool $isUnique = false, bool $isPrimary = false, array $flags = [], array $options = [])
{
$isUnique = $isUnique || $isPrimary;
......@@ -76,26 +69,15 @@ class Index extends AbstractAsset implements Constraint
}
}
/**
* @param string $column
*
* @return void
*
* @throws InvalidArgumentException
*/
protected function _addColumn($column)
protected function _addColumn(string $column) : void
{
if (! is_string($column)) {
throw new InvalidArgumentException('Expecting a string as Index Column');
}
$this->_columns[$column] = new Identifier($column);
}
/**
* {@inheritdoc}
*/
public function getColumns()
public function getColumns() : array
{
return array_keys($this->_columns);
}
......@@ -103,7 +85,7 @@ class Index extends AbstractAsset implements Constraint
/**
* {@inheritdoc}
*/
public function getQuotedColumns(AbstractPlatform $platform)
public function getQuotedColumns(AbstractPlatform $platform) : array
{
$subParts = $platform->supportsColumnLengthIndexes() && $this->hasOption('lengths')
? $this->getOption('lengths') : [];
......@@ -126,46 +108,32 @@ class Index extends AbstractAsset implements Constraint
}
/**
* @return string[]
* @return array<int, string>
*/
public function getUnquotedColumns()
public function getUnquotedColumns() : array
{
return array_map([$this, 'trimQuotes'], $this->getColumns());
}
/**
* Is the index neither unique nor primary key?
*
* @return bool
*/
public function isSimpleIndex()
public function isSimpleIndex() : bool
{
return ! $this->_isPrimary && ! $this->_isUnique;
}
/**
* @return bool
*/
public function isUnique()
public function isUnique() : bool
{
return $this->_isUnique;
}
/**
* @return bool
*/
public function isPrimary()
public function isPrimary() : bool
{
return $this->_isPrimary;
}
/**
* @param string $columnName
* @param int $pos
*
* @return bool
*/
public function hasColumnAtPosition($columnName, $pos = 0)
public function hasColumnAtPosition(string $columnName, int $pos = 0) : bool
{
$columnName = $this->trimQuotes(strtolower($columnName));
$indexColumns = array_map('strtolower', $this->getUnquotedColumns());
......@@ -176,11 +144,9 @@ class Index extends AbstractAsset implements Constraint
/**
* Checks if this index exactly spans the given column names in the correct order.
*
* @param string[] $columnNames
*
* @return bool
* @param array<int, string> $columnNames
*/
public function spansColumns(array $columnNames)
public function spansColumns(array $columnNames) : bool
{
$columns = $this->getColumns();
$numberOfColumns = count($columns);
......@@ -199,10 +165,8 @@ class Index extends AbstractAsset implements Constraint
/**
* Checks if the other index already fulfills all the indexing and constraint needs of the current one.
*
* @return bool
*/
public function isFullfilledBy(Index $other)
public function isFullfilledBy(Index $other) : bool
{
// allow the other index to be equally large only. It being larger is an option
// but it creates a problem with scenarios of the kind PRIMARY KEY(foo,bar) UNIQUE(foo)
......@@ -242,10 +206,8 @@ class Index extends AbstractAsset implements Constraint
/**
* Detects if the other index is a non-unique, non primary index that can be overwritten by this one.
*
* @return bool
*/
public function overrules(Index $other)
public function overrules(Index $other) : bool
{
if ($other->isPrimary()) {
return false;
......@@ -261,9 +223,9 @@ class Index extends AbstractAsset implements Constraint
/**
* Returns platform specific flags for indexes.
*
* @return string[]
* @return array<int, string>
*/
public function getFlags()
public function getFlags() : array
{
return array_keys($this->_flags);
}
......@@ -271,13 +233,9 @@ class Index extends AbstractAsset implements Constraint
/**
* Adds Flag for an index that translates to platform specific handling.
*
* @param string $flag
*
* @return Index
*
* @example $index->addFlag('CLUSTERED')
*/
public function addFlag($flag)
public function addFlag(string $flag) : self
{
$this->_flags[strtolower($flag)] = true;
......@@ -286,62 +244,45 @@ class Index extends AbstractAsset implements Constraint
/**
* Does this index have a specific flag?
*
* @param string $flag
*
* @return bool
*/
public function hasFlag($flag)
public function hasFlag(string $flag) : bool
{
return isset($this->_flags[strtolower($flag)]);
}
/**
* Removes a flag.
*
* @param string $flag
*
* @return void
*/
public function removeFlag($flag)
public function removeFlag(string $flag) : void
{
unset($this->_flags[strtolower($flag)]);
}
/**
* @param string $name
*
* @return bool
*/
public function hasOption($name)
public function hasOption(string $name) : bool
{
return isset($this->options[strtolower($name)]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getOption($name)
public function getOption(string $name)
{
return $this->options[strtolower($name)];
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getOptions()
public function getOptions() : array
{
return $this->options;
}
/**
* Return whether the two indexes have the same partial index
*
* @return bool
*/
private function samePartialIndex(Index $other)
private function samePartialIndex(Index $other) : bool
{
if ($this->hasOption('where') && $other->hasOption('where') && $this->getOption('where') === $other->getOption('where')) {
return true;
......
......@@ -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']);
}
......@@ -56,7 +56,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition($table)
protected function _getPortableTableDefinition(array $table) : string
{
return array_shift($table);
}
......@@ -64,7 +64,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableUserDefinition($user)
protected function _getPortableUserDefinition(array $user) : array
{
return [
'user' => $user['User'],
......@@ -100,7 +100,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableDatabaseDefinition($database)
protected function _getPortableDatabaseDefinition(array $database) : string
{
return $database['Database'];
}
......@@ -108,7 +108,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
......@@ -248,7 +248,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeysList($tableForeignKeys)
protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{
$list = [];
foreach ($tableForeignKeys as $value) {
......@@ -291,7 +291,10 @@ class MySqlSchemaManager extends AbstractSchemaManager
return $result;
}
public function listTableDetails($tableName)
/**
* {@inheritdoc}
*/
public function listTableDetails(string $tableName) : Table
{
$table = parent::listTableDetails($tableName);
......@@ -322,7 +325,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
}
/**
* @return string[]|true[]
* @return array<string, string>|array<string, true>
*/
private function parseCreateOptions(?string $string) : array
{
......
......@@ -29,7 +29,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function dropDatabase($database)
public function dropDatabase(string $database) : void
{
try {
parent::dropDatabase($database);
......@@ -58,7 +58,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : View
{
$view = array_change_key_case($view, CASE_LOWER);
......@@ -68,7 +68,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableUserDefinition($user)
protected function _getPortableUserDefinition(array $user) : array
{
$user = array_change_key_case($user, CASE_LOWER);
......@@ -80,7 +80,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition($table)
protected function _getPortableTableDefinition(array $table) : string
{
$table = array_change_key_case($table, CASE_LOWER);
......@@ -120,7 +120,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
......@@ -211,7 +211,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeysList($tableForeignKeys)
protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{
$list = [];
foreach ($tableForeignKeys as $value) {
......@@ -254,7 +254,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableSequenceDefinition($sequence)
protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{
$sequence = array_change_key_case($sequence, CASE_LOWER);
......@@ -270,17 +270,7 @@ class OracleSchemaManager extends AbstractSchemaManager
*
* @deprecated
*/
protected function _getPortableFunctionDefinition($function)
{
$function = array_change_key_case($function, CASE_LOWER);
return $function['name'];
}
/**
* {@inheritdoc}
*/
protected function _getPortableDatabaseDefinition($database)
protected function _getPortableDatabaseDefinition(array $database) : string
{
$database = array_change_key_case($database, CASE_LOWER);
......@@ -292,12 +282,8 @@ class OracleSchemaManager extends AbstractSchemaManager
*
* Calling this method without an argument or by passing NULL is deprecated.
*/
public function createDatabase($database = null)
public function createDatabase(string $database) : void
{
if ($database === null) {
$database = $this->_conn->getDatabase();
}
$params = $this->_conn->getParams();
$username = $database;
$password = $params['password'];
......@@ -309,12 +295,7 @@ class OracleSchemaManager extends AbstractSchemaManager
$this->_conn->executeUpdate($query);
}
/**
* @param string $table
*
* @return bool
*/
public function dropAutoincrement($table)
public function dropAutoincrement(string $table) : bool
{
assert($this->_platform instanceof OraclePlatform);
......@@ -329,7 +310,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function dropTable($name)
public function dropTable(string $name) : void
{
$this->tryMethod('dropAutoincrement', $name);
......@@ -341,12 +322,8 @@ class OracleSchemaManager extends AbstractSchemaManager
*
* Quotes non-uppercase identifiers explicitly to preserve case
* and thus make references to the particular identifier work.
*
* @param string $identifier The identifier to quote.
*
* @return string The quoted identifier.
*/
private function getQuotedIdentifierName($identifier)
private function getQuotedIdentifierName(string $identifier) : string
{
if (preg_match('/[a-z]/', $identifier)) {
return $this->_platform->quoteIdentifier($identifier);
......@@ -361,10 +338,8 @@ class OracleSchemaManager extends AbstractSchemaManager
* This is useful to force DROP USER operations which could fail because of active user sessions.
*
* @param string $user The name of the user to kill sessions for.
*
* @return void
*/
private function killUserSessions($user)
private function killUserSessions(string $user) : void
{
$sql = <<<SQL
SELECT
......@@ -393,7 +368,7 @@ SQL;
}
}
public function listTableDetails($tableName) : Table
public function listTableDetails(string $tableName) : Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -32,15 +32,15 @@ use function trim;
*/
class PostgreSqlSchemaManager extends AbstractSchemaManager
{
/** @var string[] */
/** @var array<int, string> */
private $existingSchemaPaths;
/**
* Gets all the existing schema names.
*
* @return string[]
* @return array<int, string>
*/
public function getSchemaNames()
public function getSchemaNames() : array
{
$statement = $this->_conn->executeQuery("SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*' AND nspname != 'information_schema'");
......@@ -52,9 +52,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
*
* This is a PostgreSQL only function.
*
* @return string[]
* @return array<int, string>
*/
public function getSchemaSearchPaths()
public function getSchemaSearchPaths() : array
{
$params = $this->_conn->getParams();
$schema = explode(',', $this->_conn->fetchColumn('SHOW search_path'));
......@@ -71,9 +71,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
*
* This is a PostgreSQL only function.
*
* @return string[]
* @return array<int, string>
*/
public function getExistingSchemaSearchPaths()
public function getExistingSchemaSearchPaths() : array
{
if ($this->existingSchemaPaths === null) {
$this->determineExistingSchemaSearchPaths();
......@@ -86,10 +86,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
* Sets or resets the order of the existing schemas in the current search path of the user.
*
* This is a PostgreSQL only function.
*
* @return void
*/
public function determineExistingSchemaSearchPaths()
public function determineExistingSchemaSearchPaths() : void
{
$names = $this->getSchemaNames();
$paths = $this->getSchemaSearchPaths();
......@@ -102,7 +100,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function dropDatabase($database)
public function dropDatabase(string $database) : void
{
try {
parent::dropDatabase($database);
......@@ -131,7 +129,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{
$onUpdate = null;
$onDelete = null;
......@@ -166,7 +164,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTriggerDefinition($trigger)
protected function _getPortableTriggerDefinition(array $trigger) : string
{
return $trigger['trigger_name'];
}
......@@ -174,7 +172,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : View
{
return new View($view['schemaname'] . '.' . $view['viewname'], $view['definition']);
}
......@@ -182,7 +180,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableUserDefinition($user)
protected function _getPortableUserDefinition(array $user) : array
{
return [
'user' => $user['usename'],
......@@ -193,7 +191,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition($table)
protected function _getPortableTableDefinition(array $table) : string
{
$schemas = $this->getExistingSchemaSearchPaths();
$firstSchema = array_shift($schemas);
......@@ -248,7 +246,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableDatabaseDefinition($database)
protected function _getPortableDatabaseDefinition(array $database) : string
{
return $database['datname'];
}
......@@ -256,7 +254,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableSequencesList($sequences)
protected function _getPortableSequencesList(array $sequences) : array
{
$sequenceDefinitions = [];
......@@ -282,7 +280,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function getPortableNamespaceDefinition(array $namespace)
protected function getPortableNamespaceDefinition(array $namespace) : string
{
return $namespace['nspname'];
}
......@@ -290,7 +288,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableSequenceDefinition($sequence)
protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{
if ($sequence['schemaname'] !== 'public') {
$sequenceName = $sequence['schemaname'] . '.' . $sequence['relname'];
......@@ -311,7 +309,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
......@@ -493,7 +491,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
return str_replace("''", "'", $default);
}
public function listTableDetails($tableName) : Table
public function listTableDetails(string $tableName) : Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -24,7 +24,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
*
* @see startDatabase
*/
public function createDatabase($database)
public function createDatabase(string $database) : void
{
parent::createDatabase($database);
$this->startDatabase($database);
......@@ -39,29 +39,19 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
*
* @see stopDatabase
*/
public function dropDatabase($database)
public function dropDatabase(string $database) : void
{
$this->tryMethod('stopDatabase', $database);
parent::dropDatabase($database);
}
/**
* Starts a database.
*
* @param string $database The name of the database to start.
*/
public function startDatabase($database)
public function startDatabase(string $database)
{
assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStartDatabaseSQL($database));
}
/**
* Stops a database.
*
* @param string $database The name of the database to stop.
*/
public function stopDatabase($database)
public function stopDatabase(string $database)
{
assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStopDatabaseSQL($database));
......@@ -70,7 +60,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableDatabaseDefinition($database)
protected function _getPortableDatabaseDefinition(array $database) : string
{
return $database['name'];
}
......@@ -78,7 +68,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableSequenceDefinition($sequence)
protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{
return new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['start_with']);
}
......@@ -86,7 +76,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'])
?? $this->_platform->getDoctrineTypeMapping($tableColumn['type']);
......@@ -141,7 +131,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition($table)
protected function _getPortableTableDefinition(array $table) : string
{
return $table['table_name'];
}
......@@ -149,7 +139,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{
return new ForeignKeyConstraint(
$tableForeignKey['local_columns'],
......@@ -163,7 +153,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeysList($tableForeignKeys)
protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{
$foreignKeys = [];
......@@ -223,7 +213,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/**
* {@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));
......
......@@ -28,7 +28,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function dropDatabase($database)
public function dropDatabase(string $database) : void
{
try {
parent::dropDatabase($database);
......@@ -57,7 +57,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableSequenceDefinition($sequence)
protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{
return new Sequence($sequence['name'], (int) $sequence['increment'], (int) $sequence['start_value']);
}
......@@ -65,7 +65,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{
$dbType = strtok($tableColumn['type'], '(), ');
assert(is_string($dbType));
......@@ -159,7 +159,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeysList($tableForeignKeys)
protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{
$foreignKeys = [];
......@@ -201,7 +201,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeyDefinition($tableForeignKey)
protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{
return new ForeignKeyConstraint(
$tableForeignKey['local_columns'],
......@@ -215,7 +215,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition($table)
protected function _getPortableTableDefinition(array $table) : string
{
if (isset($table['schema_name']) && $table['schema_name'] !== 'dbo') {
return $table['schema_name'] . '.' . $table['name'];
......@@ -227,7 +227,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableDatabaseDefinition($database)
protected function _getPortableDatabaseDefinition(array $database) : string
{
return $database['name'];
}
......@@ -235,7 +235,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function getPortableNamespaceDefinition(array $namespace)
protected function getPortableNamespaceDefinition(array $namespace) : string
{
return $namespace['name'];
}
......@@ -243,7 +243,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : View
{
// @todo
return new View($view['name'], '');
......@@ -252,7 +252,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function listTableIndexes($table)
public function listTableIndexes(string $table) : array
{
$sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
......@@ -278,7 +278,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function alterTable(TableDiff $tableDiff)
public function alterTable(TableDiff $tableDiff) : void
{
if (count($tableDiff->removedColumns) > 0) {
foreach ($tableDiff->removedColumns as $col) {
......@@ -300,13 +300,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/**
* Returns the SQL to retrieve the constraints for a given column.
*
* @param string $table
* @param string $column
*
* @return string
*/
private function getColumnConstraintSQL($table, $column)
private function getColumnConstraintSQL(string $table, string $column) : string
{
return "SELECT SysObjects.[Name]
FROM SysObjects INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab
......@@ -321,12 +316,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager
* Closes currently active connections on the given database.
*
* This is useful to force DROP DATABASE operations which could fail because of active connections.
*
* @param string $database The name of the database to close currently active connections for.
*
* @return void
*/
private function closeActiveDatabaseConnections($database)
private function closeActiveDatabaseConnections(string $database) : void
{
$database = new Identifier($database);
......@@ -338,10 +329,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
);
}
/**
* @param string $tableName
*/
public function listTableDetails($tableName) : Table
public function listTableDetails(string $tableName) : Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -47,23 +47,23 @@ class Schema extends AbstractAsset
/**
* The namespaces in this schema.
*
* @var string[]
* @var array<string, string>
*/
private $namespaces = [];
/** @var Table[] */
/** @var array<string, Table> */
protected $_tables = [];
/** @var Sequence[] */
/** @var array<string, Sequence> */
protected $_sequences = [];
/** @var SchemaConfig */
protected $_schemaConfig = false;
protected $_schemaConfig;
/**
* @param Table[] $tables
* @param Sequence[] $sequences
* @param string[] $namespaces
* @param array<Table> $tables
* @param array<Sequence> $sequences
* @param array<string> $namespaces
*/
public function __construct(
array $tables = [],
......@@ -90,20 +90,15 @@ class Schema extends AbstractAsset
}
}
/**
* @return bool
*/
public function hasExplicitForeignKeyIndexes()
public function hasExplicitForeignKeyIndexes() : bool
{
return $this->_schemaConfig->hasExplicitForeignKeyIndexes();
}
/**
* @return void
*
* @throws SchemaException
*/
protected function _addTable(Table $table)
protected function _addTable(Table $table) : void
{
$namespaceName = $table->getNamespaceName();
$tableName = $table->getFullQualifiedName($this->getName());
......@@ -123,11 +118,9 @@ class Schema extends AbstractAsset
}
/**
* @return void
*
* @throws SchemaException
*/
protected function _addSequence(Sequence $sequence)
protected function _addSequence(Sequence $sequence) : void
{
$namespaceName = $sequence->getNamespaceName();
$seqName = $sequence->getFullQualifiedName($this->getName());
......@@ -148,9 +141,9 @@ class Schema extends AbstractAsset
/**
* Returns the namespaces of this schema.
*
* @return string[] A list of namespace names.
* @return array<string, string> A list of namespace names.
*/
public function getNamespaces()
public function getNamespaces() : array
{
return $this->namespaces;
}
......@@ -158,21 +151,17 @@ class Schema extends AbstractAsset
/**
* Gets all tables of this schema.
*
* @return Table[]
* @return array<string, Table>
*/
public function getTables()
public function getTables() : array
{
return $this->_tables;
}
/**
* @param string $tableName
*
* @return Table
*
* @throws SchemaException
*/
public function getTable($tableName)
public function getTable(string $tableName) : Table
{
$tableName = $this->getFullQualifiedAssetName($tableName);
if (! isset($this->_tables[$tableName])) {
......@@ -182,12 +171,7 @@ class Schema extends AbstractAsset
return $this->_tables[$tableName];
}
/**
* @param string $name
*
* @return string
*/
private function getFullQualifiedAssetName($name)
private function getFullQualifiedAssetName(string $name) : string
{
$name = $this->getUnquotedAssetName($name);
......@@ -200,12 +184,8 @@ class Schema extends AbstractAsset
/**
* Returns the unquoted representation of a given asset name.
*
* @param string $assetName Quoted or unquoted representation of an asset name.
*
* @return string
*/
private function getUnquotedAssetName($assetName)
private function getUnquotedAssetName(string $assetName) : string
{
if ($this->isIdentifierQuoted($assetName)) {
return $this->trimQuotes($assetName);
......@@ -216,12 +196,8 @@ class Schema extends AbstractAsset
/**
* Does this schema have a namespace with the given name?
*
* @param string $namespaceName
*
* @return bool
*/
public function hasNamespace($namespaceName)
public function hasNamespace(string $namespaceName) : bool
{
$namespaceName = strtolower($this->getUnquotedAssetName($namespaceName));
......@@ -230,12 +206,8 @@ class Schema extends AbstractAsset
/**
* Does this schema have a table with the given name?
*
* @param string $tableName
*
* @return bool
*/
public function hasTable($tableName)
public function hasTable(string $tableName) : bool
{
$tableName = $this->getFullQualifiedAssetName($tableName);
......@@ -245,19 +217,14 @@ class Schema extends AbstractAsset
/**
* Gets all table names, prefixed with a schema name, even the default one if present.
*
* @return string[]
* @return array<int, string>
*/
public function getTableNames()
public function getTableNames() : array
{
return array_keys($this->_tables);
}
/**
* @param string $sequenceName
*
* @return bool
*/
public function hasSequence($sequenceName)
public function hasSequence(string $sequenceName) : bool
{
$sequenceName = $this->getFullQualifiedAssetName($sequenceName);
......@@ -265,13 +232,9 @@ class Schema extends AbstractAsset
}
/**
* @param string $sequenceName
*
* @return Sequence
*
* @throws SchemaException
*/
public function getSequence($sequenceName)
public function getSequence(string $sequenceName) : Sequence
{
$sequenceName = $this->getFullQualifiedAssetName($sequenceName);
if (! $this->hasSequence($sequenceName)) {
......@@ -282,9 +245,9 @@ class Schema extends AbstractAsset
}
/**
* @return Sequence[]
* @return array<string, Sequence>
*/
public function getSequences()
public function getSequences() : array
{
return $this->_sequences;
}
......@@ -292,13 +255,11 @@ class Schema extends AbstractAsset
/**
* Creates a new namespace.
*
* @param string $namespaceName The name of the namespace to create.
*
* @return \Doctrine\DBAL\Schema\Schema This schema instance.
* @return $this
*
* @throws SchemaException
*/
public function createNamespace($namespaceName)
public function createNamespace(string $namespaceName) : self
{
$unquotedNamespaceName = strtolower($this->getUnquotedAssetName($namespaceName));
......@@ -313,12 +274,8 @@ class Schema extends AbstractAsset
/**
* Creates a new table.
*
* @param string $tableName
*
* @return Table
*/
public function createTable($tableName)
public function createTable(string $tableName) : Table
{
$table = new Table($tableName);
$this->_addTable($table);
......@@ -333,12 +290,9 @@ class Schema extends AbstractAsset
/**
* Renames a table.
*
* @param string $oldTableName
* @param string $newTableName
*
* @return \Doctrine\DBAL\Schema\Schema
* @return $this
*/
public function renameTable($oldTableName, $newTableName)
public function renameTable(string $oldTableName, string $newTableName) : self
{
$table = $this->getTable($oldTableName);
$table->_setName($newTableName);
......@@ -352,11 +306,9 @@ class Schema extends AbstractAsset
/**
* Drops a table from the schema.
*
* @param string $tableName
*
* @return \Doctrine\DBAL\Schema\Schema
* @return $this
*/
public function dropTable($tableName)
public function dropTable(string $tableName) : self
{
$tableName = $this->getFullQualifiedAssetName($tableName);
$this->getTable($tableName);
......@@ -367,14 +319,8 @@ class Schema extends AbstractAsset
/**
* Creates a new sequence.
*
* @param string $sequenceName
* @param int $allocationSize
* @param int $initialValue
*
* @return Sequence
*/
public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1)
public function createSequence(string $sequenceName, int $allocationSize = 1, int $initialValue = 1) : Sequence
{
$seq = new Sequence($sequenceName, $allocationSize, $initialValue);
$this->_addSequence($seq);
......@@ -383,11 +329,9 @@ class Schema extends AbstractAsset
}
/**
* @param string $sequenceName
*
* @return \Doctrine\DBAL\Schema\Schema
* @return $this
*/
public function dropSequence($sequenceName)
public function dropSequence(string $sequenceName) : self
{
$sequenceName = $this->getFullQualifiedAssetName($sequenceName);
unset($this->_sequences[$sequenceName]);
......@@ -398,9 +342,9 @@ class Schema extends AbstractAsset
/**
* Returns an array of necessary SQL queries to create the schema on the given platform.
*
* @return string[]
* @return array<int, string>
*/
public function toSql(AbstractPlatform $platform)
public function toSql(AbstractPlatform $platform) : array
{
$sqlCollector = new CreateSchemaSqlCollector($platform);
$this->visit($sqlCollector);
......@@ -411,9 +355,9 @@ class Schema extends AbstractAsset
/**
* Return an array of necessary SQL queries to drop the schema on the given platform.
*
* @return string[]
* @return array<int, string>
*/
public function toDropSql(AbstractPlatform $platform)
public function toDropSql(AbstractPlatform $platform) : array
{
$dropSqlCollector = new DropSchemaSqlCollector($platform);
$this->visit($dropSqlCollector);
......@@ -422,9 +366,9 @@ class Schema extends AbstractAsset
}
/**
* @return string[]
* @return array<int, string>
*/
public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform)
public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) : array
{
$comparator = new Comparator();
$schemaDiff = $comparator->compare($this, $toSchema);
......@@ -433,9 +377,9 @@ class Schema extends AbstractAsset
}
/**
* @return string[]
* @return array<int, string>
*/
public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform)
public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) : array
{
$comparator = new Comparator();
$schemaDiff = $comparator->compare($fromSchema, $this);
......@@ -443,10 +387,7 @@ class Schema extends AbstractAsset
return $schemaDiff->toSql($platform);
}
/**
* @return void
*/
public function visit(Visitor $visitor)
public function visit(Visitor $visitor) : void
{
$visitor->acceptSchema($this);
......
......@@ -15,66 +15,44 @@ class SchemaConfig
/** @var int */
protected $maxIdentifierLength = 63;
/** @var string */
/** @var string|null */
protected $name;
/** @var mixed[] */
/** @var array<string, mixed> */
protected $defaultTableOptions = [];
/**
* @return bool
*/
public function hasExplicitForeignKeyIndexes()
public function hasExplicitForeignKeyIndexes() : bool
{
return $this->hasExplicitForeignKeyIndexes;
}
/**
* @param bool $flag
*
* @return void
*/
public function setExplicitForeignKeyIndexes($flag)
public function setExplicitForeignKeyIndexes(bool $flag) : void
{
$this->hasExplicitForeignKeyIndexes = (bool) $flag;
$this->hasExplicitForeignKeyIndexes = $flag;
}
/**
* @param int $length
*
* @return void
*/
public function setMaxIdentifierLength($length)
public function setMaxIdentifierLength(int $length) : void
{
$this->maxIdentifierLength = (int) $length;
$this->maxIdentifierLength = $length;
}
/**
* @return int
*/
public function getMaxIdentifierLength()
public function getMaxIdentifierLength() : int
{
return $this->maxIdentifierLength;
}
/**
* Gets the default namespace of schema objects.
*
* @return string
*/
public function getName()
public function getName() : ?string
{
return $this->name;
}
/**
* Sets the default namespace name of schema objects.
*
* @param string $name The value to set.
*
* @return void
*/
public function setName($name)
public function setName(string $name) : void
{
$this->name = $name;
}
......@@ -83,19 +61,17 @@ class SchemaConfig
* Gets the default options that are passed to Table instances created with
* Schema#createTable().
*
* @return mixed[]
* @return array<string, mixed>
*/
public function getDefaultTableOptions()
public function getDefaultTableOptions() : array
{
return $this->defaultTableOptions;
}
/**
* @param mixed[] $defaultTableOptions
*
* @return void
* @param array<string, mixed> $defaultTableOptions
*/
public function setDefaultTableOptions(array $defaultTableOptions)
public function setDefaultTableOptions(array $defaultTableOptions) : void
{
$this->defaultTableOptions = $defaultTableOptions;
}
......
......@@ -18,58 +18,58 @@ class SchemaDiff
/**
* All added namespaces.
*
* @var string[]
* @var array<string, string>
*/
public $newNamespaces = [];
/**
* All removed namespaces.
*
* @var string[]
* @var array<string, string>
*/
public $removedNamespaces = [];
/**
* All added tables.
*
* @var Table[]
* @var array<string, Table>
*/
public $newTables = [];
/**
* All changed tables.
*
* @var TableDiff[]
* @var array<string, TableDiff>
*/
public $changedTables = [];
/**
* All removed tables.
*
* @var Table[]
* @var array<string, Table>
*/
public $removedTables = [];
/** @var Sequence[] */
/** @var array<int, Sequence> */
public $newSequences = [];
/** @var Sequence[] */
/** @var array<int, Sequence> */
public $changedSequences = [];
/** @var Sequence[] */
/** @var array<int, Sequence> */
public $removedSequences = [];
/** @var ForeignKeyConstraint[] */
/** @var array<string|int, ForeignKeyConstraint> */
public $orphanedForeignKeys = [];
/**
* Constructs an SchemaDiff object.
*
* @param Table[] $newTables
* @param TableDiff[] $changedTables
* @param Table[] $removedTables
* @param array<string, Table> $newTables
* @param array<string, TableDiff> $changedTables
* @param array<string, Table> $removedTables
*/
public function __construct($newTables = [], $changedTables = [], $removedTables = [], ?Schema $fromSchema = null)
public function __construct(array $newTables = [], array $changedTables = [], array $removedTables = [], ?Schema $fromSchema = null)
{
$this->newTables = $newTables;
$this->changedTables = $changedTables;
......@@ -86,27 +86,25 @@ class SchemaDiff
*
* This way it is ensured that assets are deleted which might not be relevant to the metadata schema at all.
*
* @return string[]
* @return array<int, string>
*/
public function toSaveSql(AbstractPlatform $platform)
public function toSaveSql(AbstractPlatform $platform) : array
{
return $this->_toSql($platform, true);
}
/**
* @return string[]
* @return array<int, string>
*/
public function toSql(AbstractPlatform $platform)
public function toSql(AbstractPlatform $platform) : array
{
return $this->_toSql($platform, false);
}
/**
* @param bool $saveMode
*
* @return string[]
* @return array<int, string>
*/
protected function _toSql(AbstractPlatform $platform, $saveMode = false)
protected function _toSql(AbstractPlatform $platform, bool $saveMode = false) : array
{
$sql = [];
......
......@@ -22,13 +22,7 @@ class Sequence extends AbstractAsset
/** @var int|null */
protected $cache = null;
/**
* @param string $name
* @param int $allocationSize
* @param int $initialValue
* @param int|null $cache
*/
public function __construct($name, $allocationSize = 1, $initialValue = 1, $cache = null)
public function __construct(string $name, int $allocationSize = 1, int $initialValue = 1, ?int $cache = null)
{
$this->_setName($name);
$this->setAllocationSize($allocationSize);
......@@ -36,60 +30,36 @@ class Sequence extends AbstractAsset
$this->cache = $cache;
}
/**
* @return int
*/
public function getAllocationSize()
public function getAllocationSize() : int
{
return $this->allocationSize;
}
/**
* @return int
*/
public function getInitialValue()
public function getInitialValue() : int
{
return $this->initialValue;
}
/**
* @return int|null
*/
public function getCache()
public function getCache() : ?int
{
return $this->cache;
}
/**
* @param int $allocationSize
*
* @return \Doctrine\DBAL\Schema\Sequence
*/
public function setAllocationSize($allocationSize)
public function setAllocationSize(int $allocationSize) : self
{
$this->allocationSize = (int) $allocationSize ?: 1;
$this->allocationSize = $allocationSize;
return $this;
}
/**
* @param int $initialValue
*
* @return \Doctrine\DBAL\Schema\Sequence
*/
public function setInitialValue($initialValue)
public function setInitialValue(int $initialValue) : self
{
$this->initialValue = (int) $initialValue ?: 1;
$this->initialValue = $initialValue;
return $this;
}
/**
* @param int $cache
*
* @return \Doctrine\DBAL\Schema\Sequence
*/
public function setCache($cache)
public function setCache(int $cache) : self
{
$this->cache = $cache;
......@@ -101,10 +71,8 @@ class Sequence extends AbstractAsset
*
* This is used inside the comparator to not report sequences as missing,
* when the "from" schema implicitly creates the sequences.
*
* @return bool
*/
public function isAutoIncrementsFor(Table $table)
public function isAutoIncrementsFor(Table $table) : bool
{
$primaryKey = $table->getPrimaryKey();
......@@ -131,10 +99,7 @@ class Sequence extends AbstractAsset
return $tableSequenceName === $sequenceName;
}
/**
* @return void
*/
public function visit(Visitor $visitor)
public function visit(Visitor $visitor) : void
{
$visitor->acceptSequence($this);
}
......
......@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Types\StringType;
......@@ -16,6 +15,7 @@ use function array_reverse;
use function array_values;
use function count;
use function file_exists;
use function is_string;
use function preg_match;
use function preg_match_all;
use function preg_quote;
......@@ -37,7 +37,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function dropDatabase($database)
public function dropDatabase(string $database) : void
{
if (! file_exists($database)) {
return;
......@@ -49,7 +49,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function createDatabase($database)
public function createDatabase(string $database) : void
{
$params = $this->_conn->getParams();
$driver = $params['driver'];
......@@ -65,7 +65,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function renameTable($name, $newName)
public function renameTable(string $name, string $newName) : void
{
$tableDiff = new TableDiff($name);
$tableDiff->fromTable = $this->listTableDetails($name);
......@@ -76,9 +76,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) : void
{
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$table = $this->ensureTable($table);
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->addedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff);
......@@ -87,9 +90,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table)
public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) : void
{
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$table = $this->ensureTable($table);
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->changedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff);
......@@ -98,10 +104,17 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function dropForeignKey($foreignKey, $table)
public function dropForeignKey($foreignKey, $table) : void
{
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
$tableDiff->removedForeignKeys[] = $foreignKey;
$table = $this->ensureTable($table);
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
if (is_string($foreignKey)) {
$tableDiff->removedForeignKeys[] = $table->getForeignKey($foreignKey);
} else {
$tableDiff->removedForeignKeys[] = $foreignKey;
}
$this->alterTable($tableDiff);
}
......@@ -109,7 +122,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
public function listTableForeignKeys($table, $database = null)
public function listTableForeignKeys(string $table, ?string $database = null) : array
{
if ($database === null) {
$database = $this->_conn->getDatabase();
......@@ -154,7 +167,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition($table)
protected function _getPortableTableDefinition(array $table) : string
{
return $table['name'];
}
......@@ -228,18 +241,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
*
* @deprecated
*/
protected function _getPortableTableIndexDefinition($tableIndex)
{
return [
'name' => $tableIndex['name'],
'unique' => (bool) $tableIndex['unique'],
];
}
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnList($table, $database, $tableColumns)
protected function _getPortableTableColumnList(string $table, string $database, array $tableColumns) : array
{
$list = parent::_getPortableTableColumnList($table, $database, $tableColumns);
......@@ -297,7 +299,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnDefinition($tableColumn)
protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{
preg_match('/^([^()]*)\\s*(\\(((\\d+)(,\\s*(\\d+))?)\\))?/', $tableColumn['type'], $matches);
......@@ -359,7 +361,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableViewDefinition($view)
protected function _getPortableViewDefinition(array $view) : View
{
return new View($view['name'], $view['sql']);
}
......@@ -367,7 +369,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/**
* {@inheritdoc}
*/
protected function _getPortableTableForeignKeysList($tableForeignKeys)
protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{
$list = [];
foreach ($tableForeignKeys as $value) {
......@@ -415,31 +417,26 @@ class SqliteSchemaManager extends AbstractSchemaManager
return $result;
}
/**
* @param Table|string $table
*
* @return TableDiff
*
* @throws DBALException
*/
private function getTableDiffForAlterForeignKey($table)
private function getTableDiffForAlterForeignKey(Table $table) : TableDiff
{
if (! $table instanceof Table) {
$tableDetails = $this->tryMethod('listTableDetails', $table);
if ($tableDetails === false) {
throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table));
}
$table = $tableDetails;
}
$tableDiff = new TableDiff($table->getName());
$tableDiff->fromTable = $table;
return $tableDiff;
}
/**
* @param string|Table $table
*/
private function ensureTable($table) : Table
{
if (is_string($table)) {
$table = $this->listTableDetails($table);
}
return $table;
}
private function parseColumnCollationFromSQL(string $column, string $sql) : ?string
{
$pattern = '{(?:\W' . preg_quote($column) . '\W|\W' . preg_quote($this->_platform->quoteSingleIdentifier($column))
......@@ -505,10 +502,7 @@ SQL
) ?: null;
}
/**
* @param string $tableName
*/
public function listTableDetails($tableName) : Table
public function listTableDetails(string $tableName) : Table
{
$table = parent::listTableDetails($tableName);
......
......@@ -21,9 +21,9 @@ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
}
/**
* @param string[] $sql
* @param array<int, string> $sql
*/
protected function processSqlSafely(array $sql)
protected function processSqlSafely(array $sql) : void
{
foreach ($sql as $s) {
try {
......@@ -34,9 +34,9 @@ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
}
/**
* @param string[] $sql
* @param array<int, string> $sql
*/
protected function processSql(array $sql)
protected function processSql(array $sql) : void
{
foreach ($sql as $s) {
$this->conn->exec($s);
......
......@@ -15,60 +15,48 @@ interface SchemaSynchronizer
/**
* Gets the SQL statements that can be executed to create the schema.
*
* @return string[]
* @return array<int, string>
*/
public function getCreateSchema(Schema $createSchema);
public function getCreateSchema(Schema $createSchema) : array;
/**
* Gets the SQL Statements to update given schema with the underlying db.
*
* @param bool $noDrops
*
* @return string[]
* @return array<int, string>
*/
public function getUpdateSchema(Schema $toSchema, $noDrops = false);
public function getUpdateSchema(Schema $toSchema, bool $noDrops = false) : array;
/**
* Gets the SQL Statements to drop the given schema from underlying db.
*
* @return string[]
*/
public function getDropSchema(Schema $dropSchema);
public function getDropSchema(Schema $dropSchema) : array;
/**
* Gets the SQL statements to drop all schema assets from underlying db.
*
* @return string[]
* @return array<int, string>
*/
public function getDropAllSchema();
public function getDropAllSchema() : array;
/**
* Creates the Schema.
*
* @return void
*/
public function createSchema(Schema $createSchema);
public function createSchema(Schema $createSchema) : void;
/**
* Updates the Schema to new schema version.
*
* @param bool $noDrops
*
* @return void
*/
public function updateSchema(Schema $toSchema, $noDrops = false);
public function updateSchema(Schema $toSchema, bool $noDrops = false) : void;
/**
* Drops the given database schema from the underlying db.
*
* @return void
*/
public function dropSchema(Schema $dropSchema);
public function dropSchema(Schema $dropSchema) : void;
/**
* Drops all assets from the underlying db.
*
* @return void
*/
public function dropAllSchema();
public function dropAllSchema() : void;
}
......@@ -28,7 +28,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getCreateSchema(Schema $createSchema)
public function getCreateSchema(Schema $createSchema) : array
{
return $createSchema->toSql($this->platform);
}
......@@ -36,7 +36,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getUpdateSchema(Schema $toSchema, $noDrops = false)
public function getUpdateSchema(Schema $toSchema, bool $noDrops = false) : array
{
$comparator = new Comparator();
$sm = $this->conn->getSchemaManager();
......@@ -54,7 +54,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getDropSchema(Schema $dropSchema)
public function getDropSchema(Schema $dropSchema) : array
{
$visitor = new DropSchemaSqlCollector($this->platform);
$sm = $this->conn->getSchemaManager();
......@@ -114,7 +114,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getDropAllSchema()
public function getDropAllSchema() : array
{
$sm = $this->conn->getSchemaManager();
$visitor = new DropSchemaSqlCollector($this->platform);
......@@ -128,7 +128,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function createSchema(Schema $createSchema)
public function createSchema(Schema $createSchema) : void
{
$this->processSql($this->getCreateSchema($createSchema));
}
......@@ -136,7 +136,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function updateSchema(Schema $toSchema, $noDrops = false)
public function updateSchema(Schema $toSchema, bool $noDrops = false) : void
{
$this->processSql($this->getUpdateSchema($toSchema, $noDrops));
}
......@@ -144,7 +144,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function dropSchema(Schema $dropSchema)
public function dropSchema(Schema $dropSchema) : void
{
$this->processSqlSafely($this->getDropSchema($dropSchema));
}
......@@ -152,7 +152,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function dropAllSchema()
public function dropAllSchema() : void
{
$this->processSql($this->getDropAllSchema());
}
......
......@@ -59,17 +59,16 @@ class Table extends AbstractAsset
protected $_schemaConfig = null;
/**
* @param string $tableName
* @param Column[] $columns
* @param Index[] $indexes
* @param UniqueConstraint[] $uniqueConstraints
* @param ForeignKeyConstraint[] $fkConstraints
* @param mixed[] $options
* @param array<Column> $columns
* @param array<Index> $indexes
* @param array<UniqueConstraint> $uniqueConstraints
* @param array<ForeignKeyConstraint> $fkConstraints
* @param array<string, mixed> $options
*
* @throws DBALException
*/
public function __construct(
$tableName,
string $tableName,
array $columns = [],
array $indexes = [],
array $uniqueConstraints = [],
......@@ -101,10 +100,7 @@ class Table extends AbstractAsset
$this->_options = array_merge($this->_options, $options);
}
/**
* @return void
*/
public function setSchemaConfig(SchemaConfig $schemaConfig)
public function setSchemaConfig(SchemaConfig $schemaConfig) : void
{
$this->_schemaConfig = $schemaConfig;
}
......@@ -112,12 +108,9 @@ class Table extends AbstractAsset
/**
* Sets the Primary Key.
*
* @param string[] $columnNames
* @param string|false $indexName
*
* @return self
* @param array<int, string> $columnNames
*/
public function setPrimaryKey(array $columnNames, $indexName = false)
public function setPrimaryKey(array $columnNames, ?string $indexName = null) : self
{
$this->_addIndex($this->_createIndex($columnNames, $indexName ?: 'primary', true, true));
......@@ -130,14 +123,11 @@ class Table extends AbstractAsset
}
/**
* @param mixed[] $columnNames
* @param string|null $indexName
* @param string[] $flags
* @param mixed[] $options
*
* @return self
* @param array<int, string> $columnNames
* @param array<int, string> $flags
* @param array<string, mixed> $options
*/
public function addUniqueConstraint(array $columnNames, $indexName = null, array $flags = [], array $options = [])
public function addUniqueConstraint(array $columnNames, ?string $indexName = null, array $flags = [], array $options = []) : self
{
if ($indexName === null) {
$indexName = $this->_generateIdentifierName(
......@@ -151,14 +141,11 @@ class Table extends AbstractAsset
}
/**
* @param string[] $columnNames
* @param string|null $indexName
* @param string[] $flags
* @param mixed[] $options
*
* @return self
* @param array<int, string> $columnNames
* @param array<int, string> $flags
* @param array<string, mixed> $options
*/
public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = [])
public function addIndex(array $columnNames, ?string $indexName = null, array $flags = [], array $options = []) : self
{
if ($indexName === null) {
$indexName = $this->_generateIdentifierName(
......@@ -173,10 +160,8 @@ class Table extends AbstractAsset
/**
* Drops the primary key from this table.
*
* @return void
*/
public function dropPrimaryKey()
public function dropPrimaryKey() : void
{
$this->dropIndex($this->_primaryKeyName);
$this->_primaryKeyName = false;
......@@ -185,13 +170,9 @@ class Table extends AbstractAsset
/**
* Drops an index from this table.
*
* @param string $indexName The index name.
*
* @return void
*
* @throws SchemaException If the index does not exist.
*/
public function dropIndex($indexName)
public function dropIndex(string $indexName) : void
{
$indexName = $this->normalizeIdentifier($indexName);
......@@ -203,13 +184,10 @@ class Table extends AbstractAsset
}
/**
* @param string[] $columnNames
* @param string|null $indexName
* @param mixed[] $options
*
* @return self
* @param array<int, string> $columnNames
* @param array<string, mixed> $options
*/
public function addUniqueIndex(array $columnNames, $indexName = null, array $options = [])
public function addUniqueIndex(array $columnNames, ?string $indexName = null, array $options = []) : self
{
if ($indexName === null) {
$indexName = $this->_generateIdentifierName(
......@@ -229,12 +207,10 @@ class Table extends AbstractAsset
* @param string|null $newIndexName The name of the index to rename to.
* If null is given, the index name will be auto-generated.
*
* @return self This table instance.
*
* @throws SchemaException If no index exists for the given current name
* or if an index with the given new name already exists on this table.
*/
public function renameIndex($oldIndexName, $newIndexName = null)
public function renameIndex(string $oldIndexName, ?string $newIndexName = null) : self
{
$oldIndexName = $this->normalizeIdentifier($oldIndexName);
$normalizedNewIndexName = $this->normalizeIdentifier($newIndexName);
......@@ -256,7 +232,7 @@ class Table extends AbstractAsset
if ($oldIndex->isPrimary()) {
$this->dropPrimaryKey();
return $this->setPrimaryKey($oldIndex->getColumns(), $newIndexName ?? false);
return $this->setPrimaryKey($oldIndex->getColumns(), $newIndexName ?? null);
}
unset($this->_indexes[$oldIndexName]);
......@@ -271,11 +247,9 @@ class Table extends AbstractAsset
/**
* Checks if an index begins in the order of the given columns.
*
* @param string[] $columnNames
*
* @return bool
* @param array<int, string> $columnNames
*/
public function columnsAreIndexed(array $columnNames)
public function columnsAreIndexed(array $columnNames) : bool
{
foreach ($this->getIndexes() as $index) {
/** @var $index Index */
......@@ -288,13 +262,9 @@ class Table extends AbstractAsset
}
/**
* @param string $columnName
* @param string $typeName
* @param mixed[] $options
*
* @return Column
* @param array<string, mixed> $options
*/
public function addColumn($columnName, $typeName, array $options = [])
public function addColumn(string $columnName, string $typeName, array $options = []) : Column
{
$column = new Column($columnName, Type::getType($typeName), $options);
......@@ -306,12 +276,9 @@ class Table extends AbstractAsset
/**
* Change Column Details.
*
* @param string $columnName
* @param mixed[] $options
*
* @return self
* @param array<string, mixed> $options
*/
public function changeColumn($columnName, array $options)
public function changeColumn(string $columnName, array $options) : self
{
$column = $this->getColumn($columnName);
......@@ -322,12 +289,8 @@ class Table extends AbstractAsset
/**
* Drops a Column from the Table.
*
* @param string $columnName
*
* @return self
*/
public function dropColumn($columnName)
public function dropColumn(string $columnName) : self
{
$columnName = $this->normalizeIdentifier($columnName);
......@@ -341,15 +304,12 @@ class Table extends AbstractAsset
*
* Name is inferred from the local columns.
*
* @param Table|string $foreignTable Table schema instance or table name
* @param string[] $localColumnNames
* @param string[] $foreignColumnNames
* @param mixed[] $options
* @param string|null $name
*
* @return self
* @param Table|string $foreignTable Table schema instance or table name
* @param array<int, string> $localColumnNames
* @param array<int, string> $foreignColumnNames
* @param array<string, mixed> $options
*/
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null)
public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], ?string $name = null) : self
{
if (! $name) {
$name = $this->_generateIdentifierName(
......@@ -385,12 +345,9 @@ class Table extends AbstractAsset
}
/**
* @param string $name
* @param mixed $value
*
* @return self
* @param mixed $value
*/
public function addOption($name, $value)
public function addOption(string $name, $value) : self
{
$this->_options[$name] = $value;
......@@ -399,12 +356,8 @@ class Table extends AbstractAsset
/**
* Returns whether this table has a foreign key constraint with the given name.
*
* @param string $constraintName
*
* @return bool
*/
public function hasForeignKey($constraintName)
public function hasForeignKey(string $constraintName) : bool
{
$constraintName = $this->normalizeIdentifier($constraintName);
......@@ -414,13 +367,9 @@ class Table extends AbstractAsset
/**
* Returns the foreign key constraint with the given name.
*
* @param string $constraintName The constraint name.
*
* @return ForeignKeyConstraint
*
* @throws SchemaException If the foreign key does not exist.
*/
public function getForeignKey($constraintName)
public function getForeignKey(string $constraintName) : ForeignKeyConstraint
{
$constraintName = $this->normalizeIdentifier($constraintName);
......@@ -434,13 +383,9 @@ class Table extends AbstractAsset
/**
* Removes the foreign key constraint with the given name.
*
* @param string $constraintName The constraint name.
*
* @return void
*
* @throws SchemaException
*/
public function removeForeignKey($constraintName)
public function removeForeignKey(string $constraintName) : void
{
$constraintName = $this->normalizeIdentifier($constraintName);
......@@ -453,12 +398,8 @@ class Table extends AbstractAsset
/**
* Returns whether this table has a unique constraint with the given name.
*
* @param string $constraintName
*
* @return bool
*/
public function hasUniqueConstraint($constraintName)
public function hasUniqueConstraint(string $constraintName) : bool
{
$constraintName = $this->normalizeIdentifier($constraintName);
......@@ -468,13 +409,9 @@ class Table extends AbstractAsset
/**
* Returns the unique constraint with the given name.
*
* @param string $constraintName The constraint name.
*
* @return UniqueConstraint
*
* @throws SchemaException If the foreign key does not exist.
*/
public function getUniqueConstraint($constraintName)
public function getUniqueConstraint(string $constraintName) : UniqueConstraint
{
$constraintName = $this->normalizeIdentifier($constraintName);
......@@ -488,13 +425,9 @@ class Table extends AbstractAsset
/**
* Removes the unique constraint with the given name.
*
* @param string $constraintName The constraint name.
*
* @return void
*
* @throws SchemaException
*/
public function removeUniqueConstraint($constraintName)
public function removeUniqueConstraint(string $constraintName) : void
{
$constraintName = $this->normalizeIdentifier($constraintName);
......@@ -508,9 +441,9 @@ class Table extends AbstractAsset
/**
* Returns ordered list of columns (primary keys are first, then foreign keys, then the rest)
*
* @return Column[]
* @return array<string, Column>
*/
public function getColumns()
public function getColumns() : array
{
$columns = $this->_columns;
$pkCols = [];
......@@ -538,12 +471,8 @@ class Table extends AbstractAsset
/**
* Returns whether this table has a Column with the given name.
*
* @param string $columnName The column name.
*
* @return bool
*/
public function hasColumn($columnName)
public function hasColumn(string $columnName) : bool
{
$columnName = $this->normalizeIdentifier($columnName);
......@@ -553,13 +482,9 @@ class Table extends AbstractAsset
/**
* Returns the Column with the given name.
*
* @param string $columnName The column name.
*
* @return Column
*
* @throws SchemaException If the column does not exist.
*/
public function getColumn($columnName)
public function getColumn(string $columnName) : Column
{
$columnName = $this->normalizeIdentifier($columnName);
......@@ -572,10 +497,8 @@ class Table extends AbstractAsset
/**
* Returns the primary key.
*
* @return Index|null The primary key, or null if this Table has no primary key.
*/
public function getPrimaryKey()
public function getPrimaryKey() : ?Index
{
return $this->hasPrimaryKey()
? $this->getIndex($this->_primaryKeyName)
......@@ -585,11 +508,11 @@ class Table extends AbstractAsset
/**
* Returns the primary key columns.
*
* @return string[]
* @return array<int, string>
*
* @throws DBALException
*/
public function getPrimaryKeyColumns()
public function getPrimaryKeyColumns() : array
{
$primaryKey = $this->getPrimaryKey();
......@@ -602,22 +525,16 @@ class Table extends AbstractAsset
/**
* Returns whether this table has a primary key.
*
* @return bool
*/
public function hasPrimaryKey()
public function hasPrimaryKey() : bool
{
return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName);
}
/**
* Returns whether this table has an Index with the given name.
*
* @param string $indexName The index name.
*
* @return bool
*/
public function hasIndex($indexName)
public function hasIndex(string $indexName) : bool
{
$indexName = $this->normalizeIdentifier($indexName);
......@@ -627,13 +544,9 @@ class Table extends AbstractAsset
/**
* Returns the Index with the given name.
*
* @param string $indexName The index name.
*
* @return Index
*
* @throws SchemaException If the index does not exist.
*/
public function getIndex($indexName)
public function getIndex(string $indexName) : Index
{
$indexName = $this->normalizeIdentifier($indexName);
......@@ -645,9 +558,9 @@ class Table extends AbstractAsset
}
/**
* @return Index[]
* @return array<string, Index>
*/
public function getIndexes()
public function getIndexes() : array
{
return $this->_indexes;
}
......@@ -655,9 +568,9 @@ class Table extends AbstractAsset
/**
* Returns the unique constraints.
*
* @return UniqueConstraint[]
* @return array<string, UniqueConstraint>
*/
public function getUniqueConstraints()
public function getUniqueConstraints() : array
{
return $this->_uniqueConstraints;
}
......@@ -665,45 +578,35 @@ class Table extends AbstractAsset
/**
* Returns the foreign key constraints.
*
* @return ForeignKeyConstraint[]
* @return array<string, ForeignKeyConstraint>
*/
public function getForeignKeys()
{
return $this->_fkConstraints;
}
/**
* @param string $name
*
* @return bool
*/
public function hasOption($name)
public function hasOption(string $name) : bool
{
return isset($this->_options[$name]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getOption($name)
public function getOption(string $name)
{
return $this->_options[$name];
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getOptions()
public function getOptions() : array
{
return $this->_options;
}
/**
* @return void
*/
public function visit(Visitor $visitor)
public function visit(Visitor $visitor) : void
{
$visitor->acceptTable($this);
......@@ -741,10 +644,7 @@ class Table extends AbstractAsset
}
}
/**
* @return int
*/
protected function _getMaxIdentifierLength()
protected function _getMaxIdentifierLength() : int
{
return $this->_schemaConfig instanceof SchemaConfig
? $this->_schemaConfig->getMaxIdentifierLength()
......@@ -752,11 +652,9 @@ class Table extends AbstractAsset
}
/**
* @return void
*
* @throws SchemaException
*/
protected function _addColumn(Column $column)
protected function _addColumn(Column $column) : void
{
$columnName = $column->getName();
$columnName = $this->normalizeIdentifier($columnName);
......@@ -771,11 +669,9 @@ class Table extends AbstractAsset
/**
* Adds an index to the table.
*
* @return self
*
* @throws SchemaException
*/
protected function _addIndex(Index $indexCandidate)
protected function _addIndex(Index $indexCandidate) : self
{
$indexName = $indexCandidate->getName();
$indexName = $this->normalizeIdentifier($indexName);
......@@ -808,10 +704,7 @@ class Table extends AbstractAsset
return $this;
}
/**
* @return self
*/
protected function _addUniqueConstraint(UniqueConstraint $constraint)
protected function _addUniqueConstraint(UniqueConstraint $constraint) : self
{
$name = strlen($constraint->getName())
? $constraint->getName()
......@@ -847,10 +740,7 @@ class Table extends AbstractAsset
return $this;
}
/**
* @return self
*/
protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) : self
{
$constraint->setLocalTable($this);
......@@ -894,12 +784,8 @@ class Table extends AbstractAsset
* Normalizes a given identifier.
*
* Trims quotes and lowercases the given identifier.
*
* @param string|null $identifier The identifier to normalize.
*
* @return string The normalized identifier.
*/
private function normalizeIdentifier($identifier)
private function normalizeIdentifier(?string $identifier) : string
{
if ($identifier === null) {
return '';
......@@ -922,16 +808,13 @@ class Table extends AbstractAsset
}
/**
* @param mixed[] $columns
* @param string $indexName
* @param mixed[] $flags
* @param mixed[] $options
*
* @return UniqueConstraint
* @param array<string|int, string> $columns
* @param array<int, string> $flags
* @param array<string, mixed> $options
*
* @throws SchemaException
*/
private function _createUniqueConstraint(array $columns, $indexName, array $flags = [], array $options = [])
private function _createUniqueConstraint(array $columns, string $indexName, array $flags = [], array $options = []) : UniqueConstraint
{
if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) {
throw IndexNameInvalid::new($indexName);
......@@ -953,18 +836,13 @@ class Table extends AbstractAsset
}
/**
* @param mixed[] $columns
* @param string $indexName
* @param bool $isUnique
* @param bool $isPrimary
* @param string[] $flags
* @param mixed[] $options
*
* @return Index
* @param array<string|int, string> $columns
* @param array<int, string> $flags
* @param array<string, mixed> $options
*
* @throws SchemaException
*/
private function _createIndex(array $columns, $indexName, $isUnique, $isPrimary, array $flags = [], array $options = [])
private function _createIndex(array $columns, string $indexName, bool $isUnique, bool $isPrimary, array $flags = [], array $options = []) : Index
{
if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) {
throw IndexNameInvalid::new($indexName);
......
......@@ -14,83 +14,83 @@ class TableDiff
/** @var string */
public $name = null;
/** @var string|false */
public $newName = false;
/** @var string|null */
public $newName = null;
/**
* All added fields.
*
* @var Column[]
* @var array<string, Column>
*/
public $addedColumns;
/**
* All changed fields.
*
* @var ColumnDiff[]
* @var array<string, ColumnDiff>
*/
public $changedColumns = [];
/**
* All removed fields.
*
* @var Column[]
* @var array<string, Column>
*/
public $removedColumns = [];
/**
* Columns that are only renamed from key to column instance name.
*
* @var Column[]
* @var array<string, Column>
*/
public $renamedColumns = [];
/**
* All added indexes.
*
* @var Index[]
* @var array<string, Index>
*/
public $addedIndexes = [];
/**
* All changed indexes.
*
* @var Index[]
* @var array<string, Index>
*/
public $changedIndexes = [];
/**
* All removed indexes
*
* @var Index[]
* @var array<string, Index>
*/
public $removedIndexes = [];
/**
* Indexes that are only renamed but are identical otherwise.
*
* @var Index[]
* @var array<string, Index>
*/
public $renamedIndexes = [];
/**
* All added foreign key definitions
*
* @var ForeignKeyConstraint[]
* @var array<int, ForeignKeyConstraint>
*/
public $addedForeignKeys = [];
/**
* All changed foreign keys
*
* @var ForeignKeyConstraint[]
* @var array<int, ForeignKeyConstraint>
*/
public $changedForeignKeys = [];
/**
* All removed foreign keys
*
* @var ForeignKeyConstraint[]|string[]
* @var array<int, ForeignKeyConstraint>
*/
public $removedForeignKeys = [];
......@@ -100,22 +100,21 @@ class TableDiff
/**
* Constructs an TableDiff object.
*
* @param string $tableName
* @param Column[] $addedColumns
* @param ColumnDiff[] $changedColumns
* @param Column[] $removedColumns
* @param Index[] $addedIndexes
* @param Index[] $changedIndexes
* @param Index[] $removedIndexes
* @param array<string, Column> $addedColumns
* @param array<string, ColumnDiff> $changedColumns
* @param array<string, Column> $removedColumns
* @param array<string, Index> $addedIndexes
* @param array<string, Index> $changedIndexes
* @param array<string, Index> $removedIndexes
*/
public function __construct(
$tableName,
$addedColumns = [],
$changedColumns = [],
$removedColumns = [],
$addedIndexes = [],
$changedIndexes = [],
$removedIndexes = [],
string $tableName,
array $addedColumns = [],
array $changedColumns = [],
array $removedColumns = [],
array $addedIndexes = [],
array $changedIndexes = [],
array $removedIndexes = [],
?Table $fromTable = null
) {
$this->name = $tableName;
......@@ -130,23 +129,18 @@ class TableDiff
/**
* @param AbstractPlatform $platform The platform to use for retrieving this table diff's name.
*
* @return Identifier
*/
public function getName(AbstractPlatform $platform)
public function getName(AbstractPlatform $platform) : Identifier
{
return new Identifier(
$this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name
);
}
/**
* @return Identifier|false
*/
public function getNewName()
public function getNewName() : ?Identifier
{
if ($this->newName === false) {
return false;
if ($this->newName === null) {
return null;
}
return new Identifier($this->newName);
......
......@@ -16,34 +16,31 @@ class UniqueConstraint extends AbstractAsset implements Constraint
{
/**
* Asset identifier instances of the column names the unique constraint is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
* @var array<string, Identifier>
*/
protected $columns = [];
/**
* Platform specific flags
* array($flagName => true)
*
* @var true[]
* @var array<string, true>
*/
protected $flags = [];
/**
* Platform specific options
*
* @var mixed[]
* @var array<string, mixed>
*/
private $options = [];
/**
* @param string $indexName
* @param string[] $columns
* @param string[] $flags
* @param mixed[] $options
* @param array<string> $columns
* @param array<string> $flags
* @param array<string, mixed> $options
*/
public function __construct($indexName, array $columns, array $flags = [], array $options = [])
public function __construct(string $indexName, array $columns, array $flags = [], array $options = [])
{
$this->_setName($indexName);
......@@ -61,7 +58,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* {@inheritdoc}
*/
public function getColumns()
public function getColumns() : array
{
return array_keys($this->columns);
}
......@@ -69,7 +66,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* {@inheritdoc}
*/
public function getQuotedColumns(AbstractPlatform $platform)
public function getQuotedColumns(AbstractPlatform $platform) : array
{
$columns = [];
......@@ -81,9 +78,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint
}
/**
* @return string[]
* @return array<int, string>
*/
public function getUnquotedColumns()
public function getUnquotedColumns() : array
{
return array_map([$this, 'trimQuotes'], $this->getColumns());
}
......@@ -91,9 +88,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* Returns platform specific flags for unique constraint.
*
* @return string[]
* @return array<int, string>
*/
public function getFlags()
public function getFlags() : array
{
return array_keys($this->flags);
}
......@@ -101,13 +98,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* Adds flag for a unique constraint that translates to platform specific handling.
*
* @param string $flag
*
* @return self
*
* @example $uniqueConstraint->addFlag('CLUSTERED')
*/
public function addFlag($flag)
public function addFlag(string $flag) : self
{
$this->flags[strtolower($flag)] = true;
......@@ -116,52 +109,37 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/**
* Does this unique constraint have a specific flag?
*
* @param string $flag
*
* @return bool
*/
public function hasFlag($flag)
public function hasFlag(string $flag) : bool
{
return isset($this->flags[strtolower($flag)]);
}
/**
* Removes a flag.
*
* @param string $flag
*
* @return void
*/
public function removeFlag($flag)
public function removeFlag(string $flag) : void
{
unset($this->flags[strtolower($flag)]);
}
/**
* @param string $name
*
* @return bool
*/
public function hasOption($name)
public function hasOption(string $name) : bool
{
return isset($this->options[strtolower($name)]);
}
/**
* @param string $name
*
* @return mixed
*/
public function getOption($name)
public function getOption(string $name)
{
return $this->options[strtolower($name)];
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getOptions()
public function getOptions() : array
{
return $this->options;
}
......
......@@ -12,20 +12,13 @@ class View extends AbstractAsset
/** @var string */
private $sql;
/**
* @param string $name
* @param string $sql
*/
public function __construct($name, $sql)
public function __construct(string $name, string $sql)
{
$this->_setName($name);
$this->sql = $sql;
}
/**
* @return string
*/
public function getSql()
public function getSql() : string
{
return $this->sql;
}
......
......@@ -16,34 +16,34 @@ use Doctrine\DBAL\Schema\Table;
*/
class AbstractVisitor implements Visitor, NamespaceVisitor
{
public function acceptSchema(Schema $schema)
public function acceptSchema(Schema $schema) : void
{
}
/**
* {@inheritdoc}
*/
public function acceptNamespace($namespaceName)
public function acceptNamespace(string $namespaceName) : void
{
}
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
}
public function acceptColumn(Table $table, Column $column)
public function acceptColumn(Table $table, Column $column) : void
{
}
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{
}
public function acceptIndex(Table $table, Index $index)
public function acceptIndex(Table $table, Index $index) : void
{
}
public function acceptSequence(Sequence $sequence)
public function acceptSequence(Sequence $sequence) : void
{
}
}
......@@ -12,16 +12,16 @@ use function array_merge;
class CreateSchemaSqlCollector extends AbstractVisitor
{
/** @var string[] */
/** @var array<string> */
private $createNamespaceQueries = [];
/** @var string[] */
/** @var array<string> */
private $createTableQueries = [];
/** @var string[] */
/** @var array<string> */
private $createSequenceQueries = [];
/** @var string[] */
/** @var array<string> */
private $createFkConstraintQueries = [];
/** @var AbstractPlatform */
......@@ -35,7 +35,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptNamespace($namespaceName)
public function acceptNamespace(string $namespaceName) : void
{
if (! $this->platform->supportsSchemas()) {
return;
......@@ -47,7 +47,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
$this->createTableQueries = array_merge($this->createTableQueries, $this->platform->getCreateTableSQL($table));
}
......@@ -55,7 +55,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{
if (! $this->platform->supportsForeignKeyConstraints()) {
return;
......@@ -67,15 +67,12 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptSequence(Sequence $sequence)
public function acceptSequence(Sequence $sequence) : void
{
$this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence);
}
/**
* @return void
*/
public function resetQueries()
public function resetQueries() : void
{
$this->createNamespaceQueries = [];
$this->createTableQueries = [];
......@@ -86,9 +83,9 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/**
* Gets all queries collected so far.
*
* @return string[]
* @return array<string>
*/
public function getQueries()
public function getQueries() : array
{
return array_merge(
$this->createNamespaceQueries,
......
......@@ -38,7 +38,7 @@ class DropSchemaSqlCollector extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
$this->tables->attach($table);
}
......@@ -46,7 +46,7 @@ class DropSchemaSqlCollector extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{
if (strlen($fkConstraint->getName()) === 0) {
throw NamedForeignKeyRequired::new($localTable, $fkConstraint);
......@@ -58,15 +58,12 @@ class DropSchemaSqlCollector extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptSequence(Sequence $sequence)
public function acceptSequence(Sequence $sequence) : void
{
$this->sequences->attach($sequence);
}
/**
* @return void
*/
public function clearQueries()
public function clearQueries() : void
{
$this->constraints = new SplObjectStorage();
$this->sequences = new SplObjectStorage();
......@@ -74,9 +71,9 @@ class DropSchemaSqlCollector extends AbstractVisitor
}
/**
* @return string[]
* @return array<int, string>
*/
public function getQueries()
public function getQueries() : array
{
$sql = [];
......
......@@ -23,7 +23,7 @@ class Graphviz extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{
$this->output .= $this->createNodeRelation(
$fkConstraint->getLocalTableName() . ':col' . current($fkConstraint->getLocalColumns()) . ':se',
......@@ -39,7 +39,7 @@ class Graphviz extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptSchema(Schema $schema)
public function acceptSchema(Schema $schema) : void
{
$this->output = 'digraph "' . $schema->getName() . '" {' . "\n";
$this->output .= 'splines = true;' . "\n";
......@@ -52,7 +52,7 @@ class Graphviz extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
$this->output .= $this->createNode(
$table->getName(),
......@@ -63,10 +63,7 @@ class Graphviz extends AbstractVisitor
);
}
/**
* @return string
*/
private function createTableLabel(Table $table)
private function createTableLabel(Table $table) : string
{
// Start the table
$label = '<<TABLE CELLSPACING="0" BORDER="1" ALIGN="LEFT">';
......@@ -99,12 +96,9 @@ class Graphviz extends AbstractVisitor
}
/**
* @param string $name
* @param string[] $options
*
* @return string
* @param array<string, string> $options
*/
private function createNode($name, $options)
private function createNode(string $name, array $options) : string
{
$node = $name . ' [';
foreach ($options as $key => $value) {
......@@ -116,13 +110,9 @@ class Graphviz extends AbstractVisitor
}
/**
* @param string $node1
* @param string $node2
* @param string[] $options
*
* @return string
* @param array<string, string> $options
*/
private function createNodeRelation($node1, $node2, $options)
private function createNodeRelation(string $node1, string $node2, array $options) : string
{
$relation = $node1 . ' -> ' . $node2 . ' [';
foreach ($options as $key => $value) {
......@@ -135,10 +125,8 @@ class Graphviz extends AbstractVisitor
/**
* Get Graphviz Output
*
* @return string
*/
public function getOutput()
public function getOutput() : string
{
return $this->output . '}';
}
......@@ -150,12 +138,8 @@ class Graphviz extends AbstractVisitor
* and execute:
*
* neato -Tpng -o er.png er.dot
*
* @param string $filename
*
* @return void
*/
public function write($filename)
public function write(string $filename) : void
{
file_put_contents($filename, $this->getOutput());
}
......
......@@ -14,5 +14,5 @@ interface NamespaceVisitor
*
* @param string $namespaceName The schema namespace name to accept.
*/
public function acceptNamespace($namespaceName);
public function acceptNamespace(string $namespaceName) : void;
}
......@@ -28,7 +28,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptSchema(Schema $schema)
public function acceptSchema(Schema $schema) : void
{
$this->schema = $schema;
}
......@@ -36,7 +36,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
if ($table->isInDefaultNamespace($this->schema->getName())) {
return;
......@@ -48,7 +48,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptSequence(Sequence $sequence)
public function acceptSequence(Sequence $sequence) : void
{
if ($sequence->isInDefaultNamespace($this->schema->getName())) {
return;
......@@ -60,7 +60,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/**
* {@inheritdoc}
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{
// The table may already be deleted in a previous
// RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that
......
......@@ -16,33 +16,15 @@ use Doctrine\DBAL\Schema\Table;
*/
interface Visitor
{
/**
* @return void
*/
public function acceptSchema(Schema $schema);
/**
* @return void
*/
public function acceptTable(Table $table);
/**
* @return void
*/
public function acceptColumn(Table $table, Column $column);
/**
* @return void
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint);
/**
* @return void
*/
public function acceptIndex(Table $table, Index $index);
/**
* @return void
*/
public function acceptSequence(Sequence $sequence);
public function acceptSchema(Schema $schema) : void;
public function acceptTable(Table $table) : void;
public function acceptColumn(Table $table, Column $column) : void;
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void;
public function acceptIndex(Table $table, Index $index) : void;
public function acceptSequence(Sequence $sequence) : void;
}
......@@ -44,7 +44,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getCreateSchema(Schema $createSchema)
public function getCreateSchema(Schema $createSchema) : array
{
$sql = [];
......@@ -73,7 +73,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getUpdateSchema(Schema $toSchema, $noDrops = false)
public function getUpdateSchema(Schema $toSchema, bool $noDrops = false) : array
{
return $this->work($toSchema, static function ($synchronizer, $schema) use ($noDrops) {
return $synchronizer->getUpdateSchema($schema, $noDrops);
......@@ -83,7 +83,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getDropSchema(Schema $dropSchema)
public function getDropSchema(Schema $dropSchema) : array
{
return $this->work($dropSchema, static function ($synchronizer, $schema) {
return $synchronizer->getDropSchema($schema);
......@@ -93,7 +93,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function createSchema(Schema $createSchema)
public function createSchema(Schema $createSchema) : void
{
$this->processSql($this->getCreateSchema($createSchema));
}
......@@ -101,7 +101,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function updateSchema(Schema $toSchema, $noDrops = false)
public function updateSchema(Schema $toSchema, bool $noDrops = false) : void
{
$this->processSql($this->getUpdateSchema($toSchema, $noDrops));
}
......@@ -109,7 +109,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function dropSchema(Schema $dropSchema)
public function dropSchema(Schema $dropSchema) : void
{
$this->processSqlSafely($this->getDropSchema($dropSchema));
}
......@@ -117,7 +117,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function getDropAllSchema()
public function getDropAllSchema() : array
{
$this->shardManager->selectGlobal();
$globalSql = $this->synchronizer->getDropAllSchema();
......@@ -150,7 +150,7 @@ class SQLAzureFederationsSynchronizer extends AbstractSchemaSynchronizer
/**
* {@inheritdoc}
*/
public function dropAllSchema()
public function dropAllSchema() : void
{
$this->processSqlSafely($this->getDropAllSchema());
}
......
......@@ -68,7 +68,7 @@ class MultiTenantVisitor implements Visitor
/**
* {@inheritdoc}
*/
public function acceptTable(Table $table)
public function acceptTable(Table $table) : void
{
if (in_array($table->getName(), $this->excludedTables)) {
return;
......@@ -117,35 +117,35 @@ class MultiTenantVisitor implements Visitor
/**
* {@inheritdoc}
*/
public function acceptSchema(Schema $schema)
public function acceptSchema(Schema $schema) : 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
{
}
}
......@@ -41,4 +41,9 @@ class DriverTest extends AbstractDriverTest
{
return new Driver();
}
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return '';
}
}
......@@ -156,7 +156,7 @@ class NamedParametersTest extends DbalFunctionalTestCase
{
parent::setUp();
if ($this->connection->getSchemaManager()->tablesExist('ddc1372_foobar')) {
if ($this->connection->getSchemaManager()->tableExists('ddc1372_foobar')) {
return;
}
......
......@@ -39,7 +39,7 @@ class ComparatorTest extends DbalFunctionalTestCase
$onlineTable = $this->schemaManager->listTableDetails('default_value');
self::assertFalse($this->comparator->diffTable($table, $onlineTable));
self::assertNull($this->comparator->diffTable($table, $onlineTable));
}
/**
......
......@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Functional\Schema;
use DateTime;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception\DatabaseRequired;
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator;
......@@ -13,6 +15,7 @@ use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\Tests\TestUtil;
use Doctrine\Tests\Types\MySqlPointType;
class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
......@@ -72,7 +75,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator();
$diff = $comparator->diffTable($tableFetched, $table);
self::assertFalse($diff, 'no changes expected.');
self::assertNull($diff, 'no changes expected.');
}
public function testFulltextIndex() : void
......@@ -363,7 +366,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator();
self::assertFalse(
self::assertNull(
$comparator->diffTable($offlineTable, $onlineTable),
'No differences should be detected with the offline vs online schema.'
);
......@@ -442,7 +445,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator();
$diff = $comparator->diffTable($table, $onlineTable);
self::assertFalse($diff, 'Tables should be identical with column defaults.');
self::assertNull($diff, 'Tables should be identical with column defaults.');
}
public function testColumnDefaultsAreValid() : void
......@@ -517,7 +520,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Comparator();
$diff = $comparator->diffTable($table, $onlineTable);
self::assertFalse($diff, 'Tables should be identical with column defauts time and date.');
self::assertNull($diff, 'Tables should be identical with column defauts time and date.');
}
public function testEnsureTableOptionsAreReflectedInMetadata() : void
......@@ -569,4 +572,18 @@ SQL;
self::assertEquals([], $table->getOption('create_options'));
}
public function testListTableColumnsThrowsDatabaseRequired() : void
{
$params = TestUtil::getConnectionParams();
unset($params['dbname']);
$connection = DriverManager::getConnection($params);
$schemaManager = $connection->getSchemaManager();
self::expectException(DatabaseRequired::class);
self::expectExceptionMessage('A database is required for the method: Doctrine\DBAL\Schema\AbstractSchemaManager::listTableColumns');
$schemaManager->listTableColumns('users');
}
}
......@@ -300,7 +300,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$c = new Comparator();
$diff = $c->diffTable($table, $databaseTable);
self::assertFalse($diff);
self::assertNull($diff);
}
public function testListTableWithBinary() : void
......@@ -339,7 +339,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Schema\Comparator();
self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
self::assertNull($comparator->diffTable($offlineTable, $onlineTable));
}
public function testListTablesExcludesViews() : void
......@@ -385,7 +385,7 @@ class PostgreSqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$comparator = new Schema\Comparator();
self::assertFalse($comparator->diffTable($offlineTable, $onlineTable));
self::assertNull($comparator->diffTable($offlineTable, $onlineTable));
self::assertTrue($onlineTable->hasIndex('simple_partial_index'));
self::assertTrue($onlineTable->getIndex('simple_partial_index')->hasOption('where'));
self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where'));
......
......@@ -430,7 +430,7 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$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() : void
......@@ -1317,7 +1317,7 @@ abstract class SchemaManagerFunctionalTestCase extends DbalFunctionalTestCase
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_test'), $table);
self::assertFalse($tableDiff);
self::assertNull($tableDiff);
}
/**
......
......@@ -237,7 +237,7 @@ SQL;
if ($expectedComparatorDiff) {
self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff));
} else {
self::assertFalse($diff);
self::assertNull($diff);
}
}
......
......@@ -20,7 +20,7 @@ class DBAL202Test extends DbalFunctionalTestCase
$this->markTestSkipped('OCI8 only test');
}
if ($this->connection->getSchemaManager()->tablesExist('DBAL202')) {
if ($this->connection->getSchemaManager()->tableExists('DBAL202')) {
$this->connection->exec('DELETE FROM DBAL202');
} else {
$table = new Table('DBAL202');
......
......@@ -37,6 +37,6 @@ class DBAL510Test extends DbalFunctionalTestCase
$comparator = new Comparator();
$diff = $comparator->diffTable($onlineTable, $table);
self::assertFalse($diff);
self::assertNull($diff);
}
}
......@@ -484,13 +484,11 @@ class ComparatorTest extends TestCase
$seq1 = new Sequence('foo', 1, 1);
$seq2 = new Sequence('foo', 1, 2);
$seq3 = new Sequence('foo', 2, 1);
$seq4 = new Sequence('foo', '1', '1');
$c = new Comparator();
self::assertTrue($c->diffSequence($seq1, $seq2));
self::assertTrue($c->diffSequence($seq1, $seq3));
self::assertFalse($c->diffSequence($seq1, $seq4));
}
public function testRemovedSequence() : void
......@@ -653,7 +651,7 @@ class ComparatorTest extends TestCase
$c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB);
self::assertFalse($tableDiff);
self::assertNull($tableDiff);
}
public function testCompareIndexBasedOnPropertiesNotName() : void
......@@ -690,7 +688,7 @@ class ComparatorTest extends TestCase
$c = new Comparator();
$tableDiff = $c->diffTable($tableA, $tableB);
self::assertFalse($tableDiff);
self::assertNull($tableDiff);
}
public function testCompareForeignKeyRestrictNoActionAreTheSame() : void
......
......@@ -58,7 +58,7 @@ class TableDiffTest extends TestCase
{
$tableDiff = new TableDiff('foo');
self::assertFalse($tableDiff->getNewName());
self::assertNull($tableDiff->getNewName());
$tableDiff->newName = 'bar';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment