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

Merge pull request #3565 from jwage/schema-types

Add types to Schema namespace
parents ab424a1d f9dd6a3f
# Upgrade to 3.0 # 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 ## 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. 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 ...@@ -25,7 +25,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */ /** @var AbstractPlatform */
private $platform; private $platform;
/** @var string[] */ /** @var array<int, string> */
private $sql = []; private $sql = [];
public function __construct(Column $column, Table $table, AbstractPlatform $platform) public function __construct(Column $column, Table $table, AbstractPlatform $platform)
...@@ -74,7 +74,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs ...@@ -74,7 +74,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getSql() public function getSql()
{ {
......
...@@ -89,7 +89,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -89,7 +89,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getSql() 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 ...@@ -28,7 +28,7 @@ class TableGeneratorSchemaVisitor implements Visitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptSchema(Schema $schema) public function acceptSchema(Schema $schema) : void
{ {
$table = $schema->createTable($this->generatorTableName); $table = $schema->createTable($this->generatorTableName);
$table->addColumn('sequence_name', 'string'); $table->addColumn('sequence_name', 'string');
...@@ -39,35 +39,35 @@ class TableGeneratorSchemaVisitor implements Visitor ...@@ -39,35 +39,35 @@ class TableGeneratorSchemaVisitor implements Visitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptTable(Table $table) public function acceptTable(Table $table) : void
{ {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptColumn(Table $table, Column $column) public function acceptColumn(Table $table, Column $column) : void
{ {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{ {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptIndex(Table $table, Index $index) public function acceptIndex(Table $table, Index $index) : void
{ {
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptSequence(Sequence $sequence) public function acceptSequence(Sequence $sequence) : void
{ {
} }
} }
...@@ -1274,7 +1274,7 @@ abstract class AbstractPlatform ...@@ -1274,7 +1274,7 @@ abstract class AbstractPlatform
* Returns the SQL statement(s) to create a table with the specified name, columns and constraints * Returns the SQL statement(s) to create a table with the specified name, columns and constraints
* on this platform. * on this platform.
* *
* @return string[] The sequence of SQL statements. * @return array<int, string> The sequence of SQL statements.
* *
* @throws DBALException * @throws DBALException
*/ */
...@@ -1420,7 +1420,7 @@ abstract class AbstractPlatform ...@@ -1420,7 +1420,7 @@ abstract class AbstractPlatform
* @param mixed[][] $columns * @param mixed[][] $columns
* @param mixed[] $options * @param mixed[] $options
* *
* @return string[] * @return array<int, string>
*/ */
protected function _getCreateTableSQL(string $tableName, array $columns, array $options = []) : array protected function _getCreateTableSQL(string $tableName, array $columns, array $options = []) : array
{ {
...@@ -1450,7 +1450,7 @@ abstract class AbstractPlatform ...@@ -1450,7 +1450,7 @@ abstract class AbstractPlatform
} }
$query .= ')'; $query .= ')';
$sql[] = $query; $sql = [$query];
if (isset($options['foreignKeys'])) { if (isset($options['foreignKeys'])) {
foreach ((array) $options['foreignKeys'] as $definition) { foreach ((array) $options['foreignKeys'] as $definition) {
...@@ -1656,7 +1656,7 @@ abstract class AbstractPlatform ...@@ -1656,7 +1656,7 @@ abstract class AbstractPlatform
* *
* This method returns an array of SQL statements, since some platforms need several statements. * 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. * @throws DBALException If not supported on this platform.
*/ */
...@@ -1805,7 +1805,7 @@ abstract class AbstractPlatform ...@@ -1805,7 +1805,7 @@ abstract class AbstractPlatform
$sql = []; $sql = [];
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$tableName = $newName->getQuotedName($this); $tableName = $newName->getQuotedName($this);
} else { } else {
$tableName = $diff->getName($this)->getQuotedName($this); $tableName = $diff->getName($this)->getQuotedName($this);
......
...@@ -597,7 +597,7 @@ class DB2Platform extends AbstractPlatform ...@@ -597,7 +597,7 @@ class DB2Platform extends AbstractPlatform
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$sql[] = sprintf( $sql[] = sprintf(
'RENAME TABLE %s TO %s', 'RENAME TABLE %s TO %s',
$diff->getName($this)->getQuotedName($this), $diff->getName($this)->getQuotedName($this),
......
...@@ -510,7 +510,7 @@ SQL ...@@ -510,7 +510,7 @@ SQL
$queryParts = []; $queryParts = [];
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this); $queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this);
} }
...@@ -815,7 +815,7 @@ SQL ...@@ -815,7 +815,7 @@ SQL
$sql = []; $sql = [];
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$tableName = $newName->getQuotedName($this); $tableName = $newName->getQuotedName($this);
} else { } else {
$tableName = $diff->getName($this)->getQuotedName($this); $tableName = $diff->getName($this)->getQuotedName($this);
......
...@@ -461,7 +461,7 @@ class OraclePlatform extends AbstractPlatform ...@@ -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 public function getCreateAutoincrementSql(string $name, string $table, int $start = 1) : array
{ {
...@@ -854,7 +854,7 @@ SQL ...@@ -854,7 +854,7 @@ SQL
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$sql[] = sprintf( $sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s', 'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this), $diff->getName($this)->getQuotedName($this),
......
...@@ -591,7 +591,7 @@ SQL ...@@ -591,7 +591,7 @@ SQL
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$sql[] = sprintf( $sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s', 'ALTER TABLE %s RENAME TO %s',
$diff->getName($this)->getQuotedName($this), $diff->getName($this)->getQuotedName($this),
......
...@@ -190,7 +190,7 @@ class SQLAnywherePlatform extends AbstractPlatform ...@@ -190,7 +190,7 @@ class SQLAnywherePlatform extends AbstractPlatform
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . $sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' .
$this->getAlterTableRenameTableClause($newName); $this->getAlterTableRenameTableClause($newName);
} }
......
...@@ -579,7 +579,7 @@ SQL ...@@ -579,7 +579,7 @@ SQL
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'"; $sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'";
/** /**
......
...@@ -684,7 +684,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -684,7 +684,7 @@ class SqlitePlatform extends AbstractPlatform
$sql = []; $sql = [];
$tableName = $diff->getNewName(); $tableName = $diff->getNewName();
if ($tableName === false) { if ($tableName === null) {
$tableName = $diff->getName($this); $tableName = $diff->getName($this);
} }
...@@ -911,7 +911,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -911,7 +911,7 @@ class SqlitePlatform extends AbstractPlatform
$newName = $diff->getNewName(); $newName = $diff->getNewName();
if ($newName !== false) { if ($newName !== null) {
$sql[] = sprintf( $sql[] = sprintf(
'ALTER TABLE %s RENAME TO %s', 'ALTER TABLE %s RENAME TO %s',
$newTable->getQuotedName($this), $newTable->getQuotedName($this),
...@@ -993,7 +993,7 @@ class SqlitePlatform extends AbstractPlatform ...@@ -993,7 +993,7 @@ class SqlitePlatform extends AbstractPlatform
} }
if (! $this->onSchemaAlterTable($diff, $tableSql)) { if (! $this->onSchemaAlterTable($diff, $tableSql)) {
if ($diff->newName !== false) { if ($diff->newName !== null) {
$newTable = new Identifier($diff->newName); $newTable = new Identifier($diff->newName);
$sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' RENAME TO ' . $newTable->getQuotedName($this); $sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' RENAME TO ' . $newTable->getQuotedName($this);
} }
......
...@@ -39,12 +39,8 @@ abstract class AbstractAsset ...@@ -39,12 +39,8 @@ abstract class AbstractAsset
/** /**
* Sets the name of this asset. * 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)) { if ($this->isIdentifierQuoted($name)) {
$this->_quoted = true; $this->_quoted = true;
...@@ -60,12 +56,8 @@ abstract class AbstractAsset ...@@ -60,12 +56,8 @@ abstract class AbstractAsset
/** /**
* Is this asset in the default namespace? * 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; return $this->_namespace === $defaultNamespaceName || $this->_namespace === null;
} }
...@@ -74,10 +66,8 @@ abstract class AbstractAsset ...@@ -74,10 +66,8 @@ abstract class AbstractAsset
* Gets the namespace name of this asset. * Gets the namespace name of this asset.
* *
* If NULL is returned this means the default namespace is used. * If NULL is returned this means the default namespace is used.
*
* @return string|null
*/ */
public function getNamespaceName() public function getNamespaceName() : ?string
{ {
return $this->_namespace; return $this->_namespace;
} }
...@@ -85,12 +75,8 @@ abstract class AbstractAsset ...@@ -85,12 +75,8 @@ abstract class AbstractAsset
/** /**
* The shortest name is stripped of the default namespace. All other * The shortest name is stripped of the default namespace. All other
* namespaced elements are returned as full-qualified names. * 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(); $shortestName = $this->getName();
if ($this->_namespace === $defaultNamespaceName) { if ($this->_namespace === $defaultNamespaceName) {
...@@ -108,12 +94,8 @@ abstract class AbstractAsset ...@@ -108,12 +94,8 @@ abstract class AbstractAsset
* *
* Every non-namespaced element is prefixed with the default namespace * Every non-namespaced element is prefixed with the default namespace
* name which is passed as argument to this method. * 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(); $name = $this->getName();
if (! $this->_namespace) { if (! $this->_namespace) {
...@@ -125,44 +107,32 @@ abstract class AbstractAsset ...@@ -125,44 +107,32 @@ abstract class AbstractAsset
/** /**
* Checks if this asset's name is quoted. * Checks if this asset's name is quoted.
*
* @return bool
*/ */
public function isQuoted() public function isQuoted() : bool
{ {
return $this->_quoted; return $this->_quoted;
} }
/** /**
* Checks if this identifier is 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] === '['); return isset($identifier[0]) && ($identifier[0] === '`' || $identifier[0] === '"' || $identifier[0] === '[');
} }
/** /**
* Trim quotes from the identifier. * Trim quotes from the identifier.
*
* @param string $identifier
*
* @return string
*/ */
protected function trimQuotes($identifier) protected function trimQuotes(string $identifier) : string
{ {
return str_replace(['`', '"', '[', ']'], '', $identifier); return str_replace(['`', '"', '[', ']'], '', $identifier);
} }
/** /**
* Returns the name of this schema asset. * Returns the name of this schema asset.
*
* @return string
*/ */
public function getName() public function getName() : string
{ {
if ($this->_namespace) { if ($this->_namespace) {
return $this->_namespace . '.' . $this->_name; return $this->_namespace . '.' . $this->_name;
...@@ -174,10 +144,8 @@ abstract class AbstractAsset ...@@ -174,10 +144,8 @@ abstract class AbstractAsset
/** /**
* Gets the quoted representation of this asset but only if it was defined with one. Otherwise * Gets the quoted representation of this asset but only if it was defined with one. Otherwise
* return the plain unquoted value as inserted. * return the plain unquoted value as inserted.
*
* @return string
*/ */
public function getQuotedName(AbstractPlatform $platform) public function getQuotedName(AbstractPlatform $platform) : string
{ {
$keywords = $platform->getReservedKeywordsList(); $keywords = $platform->getReservedKeywordsList();
$parts = explode('.', $this->getName()); $parts = explode('.', $this->getName());
...@@ -195,13 +163,9 @@ abstract class AbstractAsset ...@@ -195,13 +163,9 @@ abstract class AbstractAsset
* however building idents automatically for foreign keys, composite keys or such can easily create * however building idents automatically for foreign keys, composite keys or such can easily create
* very long names. * very long names.
* *
* @param string[] $columnNames * @param array<int, string> $columnNames
* @param string $prefix
* @param int $maxSize
*
* @return string
*/ */
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) { $hash = implode('', array_map(static function ($column) {
return dechex(crc32($column)); return dechex(crc32($column));
......
...@@ -43,7 +43,7 @@ class Column extends AbstractAsset ...@@ -43,7 +43,7 @@ class Column extends AbstractAsset
/** @var bool */ /** @var bool */
protected $_autoincrement = false; protected $_autoincrement = false;
/** @var mixed[] */ /** @var array<string, mixed> */
protected $_platformOptions = []; protected $_platformOptions = [];
/** @var string|null */ /** @var string|null */
...@@ -52,13 +52,13 @@ class Column extends AbstractAsset ...@@ -52,13 +52,13 @@ class Column extends AbstractAsset
/** @var string|null */ /** @var string|null */
protected $_comment; protected $_comment;
/** @var mixed[] */ /** @var array<string, mixed> */
protected $_customSchemaOptions = []; protected $_customSchemaOptions = [];
/** /**
* Creates a new Column. * Creates a new Column.
* *
* @param mixed[] $options * @param array<string, mixed> $options
*/ */
public function __construct(string $name, Type $type, array $options = []) public function __construct(string $name, Type $type, array $options = [])
{ {
...@@ -68,7 +68,7 @@ class Column extends AbstractAsset ...@@ -68,7 +68,7 @@ class Column extends AbstractAsset
} }
/** /**
* @param mixed[] $options * @param array<string, mixed> $options
*/ */
public function setOptions(array $options) : self public function setOptions(array $options) : self
{ {
...@@ -154,7 +154,7 @@ class Column extends AbstractAsset ...@@ -154,7 +154,7 @@ class Column extends AbstractAsset
} }
/** /**
* @param mixed[] $platformOptions * @param array<string, mixed> $platformOptions
*/ */
public function setPlatformOptions(array $platformOptions) : self public function setPlatformOptions(array $platformOptions) : self
{ {
...@@ -224,7 +224,7 @@ class Column extends AbstractAsset ...@@ -224,7 +224,7 @@ class Column extends AbstractAsset
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function getPlatformOptions() : array public function getPlatformOptions() : array
{ {
...@@ -297,7 +297,7 @@ class Column extends AbstractAsset ...@@ -297,7 +297,7 @@ class Column extends AbstractAsset
} }
/** /**
* @param mixed[] $customSchemaOptions * @param array<string, mixed> $customSchemaOptions
*/ */
public function setCustomSchemaOptions(array $customSchemaOptions) : self public function setCustomSchemaOptions(array $customSchemaOptions) : self
{ {
...@@ -307,7 +307,7 @@ class Column extends AbstractAsset ...@@ -307,7 +307,7 @@ class Column extends AbstractAsset
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function getCustomSchemaOptions() : array public function getCustomSchemaOptions() : array
{ {
...@@ -315,7 +315,7 @@ class Column extends AbstractAsset ...@@ -315,7 +315,7 @@ class Column extends AbstractAsset
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function toArray() : array public function toArray() : array
{ {
......
...@@ -17,17 +17,16 @@ class ColumnDiff ...@@ -17,17 +17,16 @@ class ColumnDiff
/** @var Column */ /** @var Column */
public $column; public $column;
/** @var string[] */ /** @var array<int, string> */
public $changedProperties = []; public $changedProperties = [];
/** @var Column|null */ /** @var Column|null */
public $fromColumn; public $fromColumn;
/** /**
* @param string $oldColumnName * @param array<string> $changedProperties
* @param 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->oldColumnName = $oldColumnName;
$this->column = $column; $this->column = $column;
...@@ -35,20 +34,12 @@ class ColumnDiff ...@@ -35,20 +34,12 @@ class ColumnDiff
$this->fromColumn = $fromColumn; $this->fromColumn = $fromColumn;
} }
/** public function hasChanged(string $propertyName) : bool
* @param string $propertyName
*
* @return bool
*/
public function hasChanged($propertyName)
{ {
return in_array($propertyName, $this->changedProperties); return in_array($propertyName, $this->changedProperties);
} }
/** public function getOldColumnName() : Identifier
* @return Identifier
*/
public function getOldColumnName()
{ {
$quote = $this->fromColumn && $this->fromColumn->isQuoted(); $quote = $this->fromColumn && $this->fromColumn->isQuoted();
......
...@@ -21,10 +21,7 @@ use function strtolower; ...@@ -21,10 +21,7 @@ use function strtolower;
*/ */
class Comparator class Comparator
{ {
/** public static function compareSchemas(Schema $fromSchema, Schema $toSchema) : SchemaDiff
* @return SchemaDiff
*/
public static function compareSchemas(Schema $fromSchema, Schema $toSchema)
{ {
$c = new self(); $c = new self();
...@@ -37,10 +34,8 @@ class Comparator ...@@ -37,10 +34,8 @@ class Comparator
* The returned differences are returned in such a way that they contain the * 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 * operations to change the schema stored in $fromSchema to the schema that is
* stored in $toSchema. * stored in $toSchema.
*
* @return SchemaDiff
*/ */
public function compare(Schema $fromSchema, Schema $toSchema) public function compare(Schema $fromSchema, Schema $toSchema) : SchemaDiff
{ {
$diff = new SchemaDiff(); $diff = new SchemaDiff();
$diff->fromSchema = $fromSchema; $diff->fromSchema = $fromSchema;
...@@ -69,7 +64,7 @@ class Comparator ...@@ -69,7 +64,7 @@ class Comparator
$diff->newTables[$tableName] = $toSchema->getTable($tableName); $diff->newTables[$tableName] = $toSchema->getTable($tableName);
} else { } else {
$tableDifferences = $this->diffTable($fromSchema->getTable($tableName), $toSchema->getTable($tableName)); $tableDifferences = $this->diffTable($fromSchema->getTable($tableName), $toSchema->getTable($tableName));
if ($tableDifferences !== false) { if ($tableDifferences !== null) {
$diff->changedTables[$tableName] = $tableDifferences; $diff->changedTables[$tableName] = $tableDifferences;
} }
} }
...@@ -152,13 +147,7 @@ class Comparator ...@@ -152,13 +147,7 @@ class Comparator
return $diff; return $diff;
} }
/** private function isAutoIncrementSequenceInSchema(Schema $schema, Sequence $sequence) : bool
* @param Schema $schema
* @param Sequence $sequence
*
* @return bool
*/
private function isAutoIncrementSequenceInSchema($schema, $sequence)
{ {
foreach ($schema->getTables() as $table) { foreach ($schema->getTables() as $table) {
if ($sequence->isAutoIncrementsFor($table)) { if ($sequence->isAutoIncrementsFor($table)) {
...@@ -169,10 +158,7 @@ class Comparator ...@@ -169,10 +158,7 @@ class Comparator
return false; return false;
} }
/** public function diffSequence(Sequence $sequence1, Sequence $sequence2) : bool
* @return bool
*/
public function diffSequence(Sequence $sequence1, Sequence $sequence2)
{ {
if ($sequence1->getAllocationSize() !== $sequence2->getAllocationSize()) { if ($sequence1->getAllocationSize() !== $sequence2->getAllocationSize()) {
return true; return true;
...@@ -185,10 +171,8 @@ class Comparator ...@@ -185,10 +171,8 @@ class Comparator
* Returns the difference between the tables $table1 and $table2. * Returns the difference between the tables $table1 and $table2.
* *
* If there are no differences this method returns the boolean false. * 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; $changes = 0;
$tableDifferences = new TableDiff($table1->getName()); $tableDifferences = new TableDiff($table1->getName());
...@@ -294,16 +278,14 @@ class Comparator ...@@ -294,16 +278,14 @@ class Comparator
$changes++; $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 * 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. * 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 = []; $renameCandidates = [];
foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) { foreach ($tableDifferences->addedColumns as $addedColumnName => $addedColumn) {
...@@ -340,10 +322,8 @@ class Comparator ...@@ -340,10 +322,8 @@ class Comparator
/** /**
* Try to find indexes that only changed their name, rename operations maybe cheaper than add/drop * 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. * 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 = []; $renameCandidates = [];
...@@ -384,10 +364,7 @@ class Comparator ...@@ -384,10 +364,7 @@ class Comparator
} }
} }
/** public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2) : bool
* @return bool
*/
public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2)
{ {
if (array_map('strtolower', $key1->getUnquotedLocalColumns()) !== array_map('strtolower', $key2->getUnquotedLocalColumns())) { if (array_map('strtolower', $key1->getUnquotedLocalColumns()) !== array_map('strtolower', $key2->getUnquotedLocalColumns())) {
return true; return true;
...@@ -414,9 +391,9 @@ class Comparator ...@@ -414,9 +391,9 @@ class Comparator
* If there are differences this method returns $field2, otherwise the * If there are differences this method returns $field2, otherwise the
* boolean false. * 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(); $properties1 = $column1->toArray();
$properties2 = $column2->toArray(); $properties2 = $column2->toArray();
...@@ -502,10 +479,8 @@ class Comparator ...@@ -502,10 +479,8 @@ class Comparator
* *
* Compares $index1 with $index2 and returns $index2 if there are any * Compares $index1 with $index2 and returns $index2 if there are any
* differences or false in case there are no differences. * 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)); return ! ($index1->isFullfilledBy($index2) && $index2->isFullfilledBy($index1));
} }
......
...@@ -11,23 +11,17 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -11,23 +11,17 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
*/ */
interface Constraint interface Constraint
{ {
/** public function getName() : string;
* @return string
*/
public function getName();
/** public function getQuotedName(AbstractPlatform $platform) : string;
* @return string
*/
public function getQuotedName(AbstractPlatform $platform);
/** /**
* Returns the names of the referencing table columns * Returns the names of the referencing table columns
* the constraint is associated with. * 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 * Returns the quoted representation of the column names
...@@ -39,7 +33,7 @@ interface Constraint ...@@ -39,7 +33,7 @@ interface Constraint
* *
* @param AbstractPlatform $platform The platform to use for quotation. * @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 ...@@ -43,7 +43,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{ {
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER); $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
...@@ -105,7 +105,7 @@ class DB2SchemaManager extends AbstractSchemaManager ...@@ -105,7 +105,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTablesList($tables) protected function _getPortableTablesList(array $tables) : array
{ {
$tableNames = []; $tableNames = [];
foreach ($tables as $tableRow) { foreach ($tables as $tableRow) {
...@@ -132,7 +132,7 @@ class DB2SchemaManager extends AbstractSchemaManager ...@@ -132,7 +132,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeyDefinition($tableForeignKey) protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{ {
return new ForeignKeyConstraint( return new ForeignKeyConstraint(
$tableForeignKey['local_columns'], $tableForeignKey['local_columns'],
...@@ -146,7 +146,7 @@ class DB2SchemaManager extends AbstractSchemaManager ...@@ -146,7 +146,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{ {
$foreignKeys = []; $foreignKeys = [];
...@@ -176,7 +176,7 @@ class DB2SchemaManager extends AbstractSchemaManager ...@@ -176,7 +176,7 @@ class DB2SchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition(array $view) : View
{ {
$view = array_change_key_case($view, CASE_LOWER); $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 // 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 ...@@ -191,7 +191,7 @@ class DB2SchemaManager extends AbstractSchemaManager
return new View($view['name'], $sql); return new View($view['name'], $sql);
} }
public function listTableDetails($tableName) : Table public function listTableDetails(string $tableName) : Table
{ {
$table = parent::listTableDetails($tableName); $table = parent::listTableDetails($tableName);
......
...@@ -16,7 +16,7 @@ class Identifier extends AbstractAsset ...@@ -16,7 +16,7 @@ class Identifier extends AbstractAsset
* @param string $identifier Identifier name to wrap. * @param string $identifier Identifier name to wrap.
* @param bool $quote Whether to force quoting the given identifier. * @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); $this->_setName($identifier);
......
...@@ -5,23 +5,20 @@ declare(strict_types=1); ...@@ -5,23 +5,20 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use InvalidArgumentException;
use function array_filter; use function array_filter;
use function array_keys; use function array_keys;
use function array_map; use function array_map;
use function array_search; use function array_search;
use function array_shift; use function array_shift;
use function count; use function count;
use function is_string;
use function strtolower; use function strtolower;
class Index extends AbstractAsset implements Constraint class Index extends AbstractAsset implements Constraint
{ {
/** /**
* Asset identifier instances of the column names the index is associated with. * Asset identifier instances of the column names the index is associated with.
* array($columnName => Identifier)
* *
* @var Identifier[] * @var array<string, Identifier>
*/ */
protected $_columns = []; protected $_columns = [];
...@@ -33,9 +30,8 @@ class Index extends AbstractAsset implements Constraint ...@@ -33,9 +30,8 @@ class Index extends AbstractAsset implements Constraint
/** /**
* Platform specific flags for indexes. * Platform specific flags for indexes.
* array($flagName => true)
* *
* @var true[] * @var array<string, true>
*/ */
protected $_flags = []; protected $_flags = [];
...@@ -43,19 +39,16 @@ class Index extends AbstractAsset implements Constraint ...@@ -43,19 +39,16 @@ class Index extends AbstractAsset implements Constraint
* Platform specific options * Platform specific options
* *
* @todo $_flags should eventually be refactored into options * @todo $_flags should eventually be refactored into options
* @var mixed[] * @var array<string, mixed>
*/ */
private $options = []; private $options = [];
/** /**
* @param string $indexName * @param array<int, string> $columns
* @param string[] $columns * @param array<int, string> $flags
* @param bool $isUnique * @param array<string, mixed> $options
* @param bool $isPrimary
* @param string[] $flags
* @param 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; $isUnique = $isUnique || $isPrimary;
...@@ -76,26 +69,15 @@ class Index extends AbstractAsset implements Constraint ...@@ -76,26 +69,15 @@ class Index extends AbstractAsset implements Constraint
} }
} }
/** protected function _addColumn(string $column) : void
* @param string $column
*
* @return void
*
* @throws InvalidArgumentException
*/
protected function _addColumn($column)
{ {
if (! is_string($column)) {
throw new InvalidArgumentException('Expecting a string as Index Column');
}
$this->_columns[$column] = new Identifier($column); $this->_columns[$column] = new Identifier($column);
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumns() public function getColumns() : array
{ {
return array_keys($this->_columns); return array_keys($this->_columns);
} }
...@@ -103,7 +85,7 @@ class Index extends AbstractAsset implements Constraint ...@@ -103,7 +85,7 @@ class Index extends AbstractAsset implements Constraint
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getQuotedColumns(AbstractPlatform $platform) public function getQuotedColumns(AbstractPlatform $platform) : array
{ {
$subParts = $platform->supportsColumnLengthIndexes() && $this->hasOption('lengths') $subParts = $platform->supportsColumnLengthIndexes() && $this->hasOption('lengths')
? $this->getOption('lengths') : []; ? $this->getOption('lengths') : [];
...@@ -126,46 +108,32 @@ class Index extends AbstractAsset implements Constraint ...@@ -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()); return array_map([$this, 'trimQuotes'], $this->getColumns());
} }
/** /**
* Is the index neither unique nor primary key? * Is the index neither unique nor primary key?
*
* @return bool
*/ */
public function isSimpleIndex() public function isSimpleIndex() : bool
{ {
return ! $this->_isPrimary && ! $this->_isUnique; return ! $this->_isPrimary && ! $this->_isUnique;
} }
/** public function isUnique() : bool
* @return bool
*/
public function isUnique()
{ {
return $this->_isUnique; return $this->_isUnique;
} }
/** public function isPrimary() : bool
* @return bool
*/
public function isPrimary()
{ {
return $this->_isPrimary; return $this->_isPrimary;
} }
/** public function hasColumnAtPosition(string $columnName, int $pos = 0) : bool
* @param string $columnName
* @param int $pos
*
* @return bool
*/
public function hasColumnAtPosition($columnName, $pos = 0)
{ {
$columnName = $this->trimQuotes(strtolower($columnName)); $columnName = $this->trimQuotes(strtolower($columnName));
$indexColumns = array_map('strtolower', $this->getUnquotedColumns()); $indexColumns = array_map('strtolower', $this->getUnquotedColumns());
...@@ -176,11 +144,9 @@ class Index extends AbstractAsset implements Constraint ...@@ -176,11 +144,9 @@ class Index extends AbstractAsset implements Constraint
/** /**
* Checks if this index exactly spans the given column names in the correct order. * Checks if this index exactly spans the given column names in the correct order.
* *
* @param string[] $columnNames * @param array<int, string> $columnNames
*
* @return bool
*/ */
public function spansColumns(array $columnNames) public function spansColumns(array $columnNames) : bool
{ {
$columns = $this->getColumns(); $columns = $this->getColumns();
$numberOfColumns = count($columns); $numberOfColumns = count($columns);
...@@ -199,10 +165,8 @@ class Index extends AbstractAsset implements Constraint ...@@ -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. * 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 // 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) // 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 ...@@ -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. * 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()) { if ($other->isPrimary()) {
return false; return false;
...@@ -261,9 +223,9 @@ class Index extends AbstractAsset implements Constraint ...@@ -261,9 +223,9 @@ class Index extends AbstractAsset implements Constraint
/** /**
* Returns platform specific flags for indexes. * Returns platform specific flags for indexes.
* *
* @return string[] * @return array<int, string>
*/ */
public function getFlags() public function getFlags() : array
{ {
return array_keys($this->_flags); return array_keys($this->_flags);
} }
...@@ -271,13 +233,9 @@ class Index extends AbstractAsset implements Constraint ...@@ -271,13 +233,9 @@ class Index extends AbstractAsset implements Constraint
/** /**
* Adds Flag for an index that translates to platform specific handling. * Adds Flag for an index that translates to platform specific handling.
* *
* @param string $flag
*
* @return Index
*
* @example $index->addFlag('CLUSTERED') * @example $index->addFlag('CLUSTERED')
*/ */
public function addFlag($flag) public function addFlag(string $flag) : self
{ {
$this->_flags[strtolower($flag)] = true; $this->_flags[strtolower($flag)] = true;
...@@ -286,62 +244,45 @@ class Index extends AbstractAsset implements Constraint ...@@ -286,62 +244,45 @@ class Index extends AbstractAsset implements Constraint
/** /**
* Does this index have a specific flag? * 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)]); return isset($this->_flags[strtolower($flag)]);
} }
/** /**
* Removes a flag. * Removes a flag.
*
* @param string $flag
*
* @return void
*/ */
public function removeFlag($flag) public function removeFlag(string $flag) : void
{ {
unset($this->_flags[strtolower($flag)]); unset($this->_flags[strtolower($flag)]);
} }
/** public function hasOption(string $name) : bool
* @param string $name
*
* @return bool
*/
public function hasOption($name)
{ {
return isset($this->options[strtolower($name)]); return isset($this->options[strtolower($name)]);
} }
/** /**
* @param string $name
*
* @return mixed * @return mixed
*/ */
public function getOption($name) public function getOption(string $name)
{ {
return $this->options[strtolower($name)]; return $this->options[strtolower($name)];
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function getOptions() public function getOptions() : array
{ {
return $this->options; return $this->options;
} }
/** /**
* Return whether the two indexes have the same partial index * 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')) { if ($this->hasOption('where') && $other->hasOption('where') && $this->getOption('where') === $other->getOption('where')) {
return true; return true;
......
...@@ -48,7 +48,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -48,7 +48,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition(array $view) : View
{ {
return new View($view['TABLE_NAME'], $view['VIEW_DEFINITION']); return new View($view['TABLE_NAME'], $view['VIEW_DEFINITION']);
} }
...@@ -56,7 +56,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -56,7 +56,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableDefinition($table) protected function _getPortableTableDefinition(array $table) : string
{ {
return array_shift($table); return array_shift($table);
} }
...@@ -64,7 +64,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -64,7 +64,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableUserDefinition($user) protected function _getPortableUserDefinition(array $user) : array
{ {
return [ return [
'user' => $user['User'], 'user' => $user['User'],
...@@ -100,7 +100,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -100,7 +100,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableDatabaseDefinition($database) protected function _getPortableDatabaseDefinition(array $database) : string
{ {
return $database['Database']; return $database['Database'];
} }
...@@ -108,7 +108,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -108,7 +108,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{ {
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER); $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
...@@ -248,7 +248,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -248,7 +248,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{ {
$list = []; $list = [];
foreach ($tableForeignKeys as $value) { foreach ($tableForeignKeys as $value) {
...@@ -291,7 +291,10 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -291,7 +291,10 @@ class MySqlSchemaManager extends AbstractSchemaManager
return $result; return $result;
} }
public function listTableDetails($tableName) /**
* {@inheritdoc}
*/
public function listTableDetails(string $tableName) : Table
{ {
$table = parent::listTableDetails($tableName); $table = parent::listTableDetails($tableName);
...@@ -322,7 +325,7 @@ class MySqlSchemaManager extends AbstractSchemaManager ...@@ -322,7 +325,7 @@ class MySqlSchemaManager extends AbstractSchemaManager
} }
/** /**
* @return string[]|true[] * @return array<string, string>|array<string, true>
*/ */
private function parseCreateOptions(?string $string) : array private function parseCreateOptions(?string $string) : array
{ {
......
...@@ -29,7 +29,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -29,7 +29,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropDatabase($database) public function dropDatabase(string $database) : void
{ {
try { try {
parent::dropDatabase($database); parent::dropDatabase($database);
...@@ -58,7 +58,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -58,7 +58,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition(array $view) : View
{ {
$view = array_change_key_case($view, CASE_LOWER); $view = array_change_key_case($view, CASE_LOWER);
...@@ -68,7 +68,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -68,7 +68,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableUserDefinition($user) protected function _getPortableUserDefinition(array $user) : array
{ {
$user = array_change_key_case($user, CASE_LOWER); $user = array_change_key_case($user, CASE_LOWER);
...@@ -80,7 +80,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -80,7 +80,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableDefinition($table) protected function _getPortableTableDefinition(array $table) : string
{ {
$table = array_change_key_case($table, CASE_LOWER); $table = array_change_key_case($table, CASE_LOWER);
...@@ -120,7 +120,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -120,7 +120,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{ {
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER); $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
...@@ -211,7 +211,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -211,7 +211,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{ {
$list = []; $list = [];
foreach ($tableForeignKeys as $value) { foreach ($tableForeignKeys as $value) {
...@@ -254,7 +254,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -254,7 +254,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{ {
$sequence = array_change_key_case($sequence, CASE_LOWER); $sequence = array_change_key_case($sequence, CASE_LOWER);
...@@ -270,17 +270,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -270,17 +270,7 @@ class OracleSchemaManager extends AbstractSchemaManager
* *
* @deprecated * @deprecated
*/ */
protected function _getPortableFunctionDefinition($function) protected function _getPortableDatabaseDefinition(array $database) : string
{
$function = array_change_key_case($function, CASE_LOWER);
return $function['name'];
}
/**
* {@inheritdoc}
*/
protected function _getPortableDatabaseDefinition($database)
{ {
$database = array_change_key_case($database, CASE_LOWER); $database = array_change_key_case($database, CASE_LOWER);
...@@ -292,12 +282,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -292,12 +282,8 @@ class OracleSchemaManager extends AbstractSchemaManager
* *
* Calling this method without an argument or by passing NULL is deprecated. * 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(); $params = $this->_conn->getParams();
$username = $database; $username = $database;
$password = $params['password']; $password = $params['password'];
...@@ -309,12 +295,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -309,12 +295,7 @@ class OracleSchemaManager extends AbstractSchemaManager
$this->_conn->executeUpdate($query); $this->_conn->executeUpdate($query);
} }
/** public function dropAutoincrement(string $table) : bool
* @param string $table
*
* @return bool
*/
public function dropAutoincrement($table)
{ {
assert($this->_platform instanceof OraclePlatform); assert($this->_platform instanceof OraclePlatform);
...@@ -329,7 +310,7 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -329,7 +310,7 @@ class OracleSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropTable($name) public function dropTable(string $name) : void
{ {
$this->tryMethod('dropAutoincrement', $name); $this->tryMethod('dropAutoincrement', $name);
...@@ -341,12 +322,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -341,12 +322,8 @@ class OracleSchemaManager extends AbstractSchemaManager
* *
* Quotes non-uppercase identifiers explicitly to preserve case * Quotes non-uppercase identifiers explicitly to preserve case
* and thus make references to the particular identifier work. * 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)) { if (preg_match('/[a-z]/', $identifier)) {
return $this->_platform->quoteIdentifier($identifier); return $this->_platform->quoteIdentifier($identifier);
...@@ -361,10 +338,8 @@ class OracleSchemaManager extends AbstractSchemaManager ...@@ -361,10 +338,8 @@ class OracleSchemaManager extends AbstractSchemaManager
* This is useful to force DROP USER operations which could fail because of active user sessions. * 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. * @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 $sql = <<<SQL
SELECT SELECT
...@@ -393,7 +368,7 @@ SQL; ...@@ -393,7 +368,7 @@ SQL;
} }
} }
public function listTableDetails($tableName) : Table public function listTableDetails(string $tableName) : Table
{ {
$table = parent::listTableDetails($tableName); $table = parent::listTableDetails($tableName);
......
...@@ -32,15 +32,15 @@ use function trim; ...@@ -32,15 +32,15 @@ use function trim;
*/ */
class PostgreSqlSchemaManager extends AbstractSchemaManager class PostgreSqlSchemaManager extends AbstractSchemaManager
{ {
/** @var string[] */ /** @var array<int, string> */
private $existingSchemaPaths; private $existingSchemaPaths;
/** /**
* Gets all the existing schema names. * 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'"); $statement = $this->_conn->executeQuery("SELECT nspname FROM pg_namespace WHERE nspname !~ '^pg_.*' AND nspname != 'information_schema'");
...@@ -52,9 +52,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -52,9 +52,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
* *
* This is a PostgreSQL only function. * This is a PostgreSQL only function.
* *
* @return string[] * @return array<int, string>
*/ */
public function getSchemaSearchPaths() public function getSchemaSearchPaths() : array
{ {
$params = $this->_conn->getParams(); $params = $this->_conn->getParams();
$schema = explode(',', $this->_conn->fetchColumn('SHOW search_path')); $schema = explode(',', $this->_conn->fetchColumn('SHOW search_path'));
...@@ -71,9 +71,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -71,9 +71,9 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
* *
* This is a PostgreSQL only function. * This is a PostgreSQL only function.
* *
* @return string[] * @return array<int, string>
*/ */
public function getExistingSchemaSearchPaths() public function getExistingSchemaSearchPaths() : array
{ {
if ($this->existingSchemaPaths === null) { if ($this->existingSchemaPaths === null) {
$this->determineExistingSchemaSearchPaths(); $this->determineExistingSchemaSearchPaths();
...@@ -86,10 +86,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -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. * Sets or resets the order of the existing schemas in the current search path of the user.
* *
* This is a PostgreSQL only function. * This is a PostgreSQL only function.
*
* @return void
*/ */
public function determineExistingSchemaSearchPaths() public function determineExistingSchemaSearchPaths() : void
{ {
$names = $this->getSchemaNames(); $names = $this->getSchemaNames();
$paths = $this->getSchemaSearchPaths(); $paths = $this->getSchemaSearchPaths();
...@@ -102,7 +100,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -102,7 +100,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropDatabase($database) public function dropDatabase(string $database) : void
{ {
try { try {
parent::dropDatabase($database); parent::dropDatabase($database);
...@@ -131,7 +129,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -131,7 +129,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeyDefinition($tableForeignKey) protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{ {
$onUpdate = null; $onUpdate = null;
$onDelete = null; $onDelete = null;
...@@ -166,7 +164,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -166,7 +164,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTriggerDefinition($trigger) protected function _getPortableTriggerDefinition(array $trigger) : string
{ {
return $trigger['trigger_name']; return $trigger['trigger_name'];
} }
...@@ -174,7 +172,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -174,7 +172,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition(array $view) : View
{ {
return new View($view['schemaname'] . '.' . $view['viewname'], $view['definition']); return new View($view['schemaname'] . '.' . $view['viewname'], $view['definition']);
} }
...@@ -182,7 +180,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -182,7 +180,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableUserDefinition($user) protected function _getPortableUserDefinition(array $user) : array
{ {
return [ return [
'user' => $user['usename'], 'user' => $user['usename'],
...@@ -193,7 +191,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -193,7 +191,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableDefinition($table) protected function _getPortableTableDefinition(array $table) : string
{ {
$schemas = $this->getExistingSchemaSearchPaths(); $schemas = $this->getExistingSchemaSearchPaths();
$firstSchema = array_shift($schemas); $firstSchema = array_shift($schemas);
...@@ -248,7 +246,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -248,7 +246,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableDatabaseDefinition($database) protected function _getPortableDatabaseDefinition(array $database) : string
{ {
return $database['datname']; return $database['datname'];
} }
...@@ -256,7 +254,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -256,7 +254,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableSequencesList($sequences) protected function _getPortableSequencesList(array $sequences) : array
{ {
$sequenceDefinitions = []; $sequenceDefinitions = [];
...@@ -282,7 +280,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -282,7 +280,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getPortableNamespaceDefinition(array $namespace) protected function getPortableNamespaceDefinition(array $namespace) : string
{ {
return $namespace['nspname']; return $namespace['nspname'];
} }
...@@ -290,7 +288,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -290,7 +288,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{ {
if ($sequence['schemaname'] !== 'public') { if ($sequence['schemaname'] !== 'public') {
$sequenceName = $sequence['schemaname'] . '.' . $sequence['relname']; $sequenceName = $sequence['schemaname'] . '.' . $sequence['relname'];
...@@ -311,7 +309,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -311,7 +309,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{ {
$tableColumn = array_change_key_case($tableColumn, CASE_LOWER); $tableColumn = array_change_key_case($tableColumn, CASE_LOWER);
...@@ -493,7 +491,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager ...@@ -493,7 +491,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager
return str_replace("''", "'", $default); return str_replace("''", "'", $default);
} }
public function listTableDetails($tableName) : Table public function listTableDetails(string $tableName) : Table
{ {
$table = parent::listTableDetails($tableName); $table = parent::listTableDetails($tableName);
......
...@@ -24,7 +24,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -24,7 +24,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
* *
* @see startDatabase * @see startDatabase
*/ */
public function createDatabase($database) public function createDatabase(string $database) : void
{ {
parent::createDatabase($database); parent::createDatabase($database);
$this->startDatabase($database); $this->startDatabase($database);
...@@ -39,29 +39,19 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -39,29 +39,19 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
* *
* @see stopDatabase * @see stopDatabase
*/ */
public function dropDatabase($database) public function dropDatabase(string $database) : void
{ {
$this->tryMethod('stopDatabase', $database); $this->tryMethod('stopDatabase', $database);
parent::dropDatabase($database); parent::dropDatabase($database);
} }
/** public function startDatabase(string $database)
* Starts a database.
*
* @param string $database The name of the database to start.
*/
public function startDatabase($database)
{ {
assert($this->_platform instanceof SQLAnywherePlatform); assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStartDatabaseSQL($database)); $this->_execSql($this->_platform->getStartDatabaseSQL($database));
} }
/** public function stopDatabase(string $database)
* Stops a database.
*
* @param string $database The name of the database to stop.
*/
public function stopDatabase($database)
{ {
assert($this->_platform instanceof SQLAnywherePlatform); assert($this->_platform instanceof SQLAnywherePlatform);
$this->_execSql($this->_platform->getStopDatabaseSQL($database)); $this->_execSql($this->_platform->getStopDatabaseSQL($database));
...@@ -70,7 +60,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -70,7 +60,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableDatabaseDefinition($database) protected function _getPortableDatabaseDefinition(array $database) : string
{ {
return $database['name']; return $database['name'];
} }
...@@ -78,7 +68,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -78,7 +68,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{ {
return new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['start_with']); return new Sequence($sequence['sequence_name'], $sequence['increment_by'], $sequence['start_with']);
} }
...@@ -86,7 +76,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -86,7 +76,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{ {
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment']) $type = $this->extractDoctrineTypeFromComment($tableColumn['comment'])
?? $this->_platform->getDoctrineTypeMapping($tableColumn['type']); ?? $this->_platform->getDoctrineTypeMapping($tableColumn['type']);
...@@ -141,7 +131,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -141,7 +131,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableDefinition($table) protected function _getPortableTableDefinition(array $table) : string
{ {
return $table['table_name']; return $table['table_name'];
} }
...@@ -149,7 +139,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -149,7 +139,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeyDefinition($tableForeignKey) protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{ {
return new ForeignKeyConstraint( return new ForeignKeyConstraint(
$tableForeignKey['local_columns'], $tableForeignKey['local_columns'],
...@@ -163,7 +153,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -163,7 +153,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{ {
$foreignKeys = []; $foreignKeys = [];
...@@ -223,7 +213,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager ...@@ -223,7 +213,7 @@ class SQLAnywhereSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition(array $view) : View
{ {
$definition = preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def']); $definition = preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def']);
assert(is_string($definition)); assert(is_string($definition));
......
...@@ -28,7 +28,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -28,7 +28,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropDatabase($database) public function dropDatabase(string $database) : void
{ {
try { try {
parent::dropDatabase($database); parent::dropDatabase($database);
...@@ -57,7 +57,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -57,7 +57,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableSequenceDefinition($sequence) protected function _getPortableSequenceDefinition(array $sequence) : Sequence
{ {
return new Sequence($sequence['name'], (int) $sequence['increment'], (int) $sequence['start_value']); return new Sequence($sequence['name'], (int) $sequence['increment'], (int) $sequence['start_value']);
} }
...@@ -65,7 +65,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -65,7 +65,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{ {
$dbType = strtok($tableColumn['type'], '(), '); $dbType = strtok($tableColumn['type'], '(), ');
assert(is_string($dbType)); assert(is_string($dbType));
...@@ -159,7 +159,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -159,7 +159,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{ {
$foreignKeys = []; $foreignKeys = [];
...@@ -201,7 +201,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -201,7 +201,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeyDefinition($tableForeignKey) protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint
{ {
return new ForeignKeyConstraint( return new ForeignKeyConstraint(
$tableForeignKey['local_columns'], $tableForeignKey['local_columns'],
...@@ -215,7 +215,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -215,7 +215,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableDefinition($table) protected function _getPortableTableDefinition(array $table) : string
{ {
if (isset($table['schema_name']) && $table['schema_name'] !== 'dbo') { if (isset($table['schema_name']) && $table['schema_name'] !== 'dbo') {
return $table['schema_name'] . '.' . $table['name']; return $table['schema_name'] . '.' . $table['name'];
...@@ -227,7 +227,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -227,7 +227,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableDatabaseDefinition($database) protected function _getPortableDatabaseDefinition(array $database) : string
{ {
return $database['name']; return $database['name'];
} }
...@@ -235,7 +235,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -235,7 +235,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function getPortableNamespaceDefinition(array $namespace) protected function getPortableNamespaceDefinition(array $namespace) : string
{ {
return $namespace['name']; return $namespace['name'];
} }
...@@ -243,7 +243,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -243,7 +243,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition(array $view) : View
{ {
// @todo // @todo
return new View($view['name'], ''); return new View($view['name'], '');
...@@ -252,7 +252,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -252,7 +252,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function listTableIndexes($table) public function listTableIndexes(string $table) : array
{ {
$sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase()); $sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase());
...@@ -278,7 +278,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -278,7 +278,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function alterTable(TableDiff $tableDiff) public function alterTable(TableDiff $tableDiff) : void
{ {
if (count($tableDiff->removedColumns) > 0) { if (count($tableDiff->removedColumns) > 0) {
foreach ($tableDiff->removedColumns as $col) { foreach ($tableDiff->removedColumns as $col) {
...@@ -300,13 +300,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -300,13 +300,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager
/** /**
* Returns the SQL to retrieve the constraints for a given column. * 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] return "SELECT SysObjects.[Name]
FROM SysObjects INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab FROM SysObjects INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab
...@@ -321,12 +316,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -321,12 +316,8 @@ class SQLServerSchemaManager extends AbstractSchemaManager
* Closes currently active connections on the given database. * Closes currently active connections on the given database.
* *
* This is useful to force DROP DATABASE operations which could fail because of active connections. * 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); $database = new Identifier($database);
...@@ -338,10 +329,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager ...@@ -338,10 +329,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager
); );
} }
/** public function listTableDetails(string $tableName) : Table
* @param string $tableName
*/
public function listTableDetails($tableName) : Table
{ {
$table = parent::listTableDetails($tableName); $table = parent::listTableDetails($tableName);
......
This diff is collapsed.
...@@ -15,66 +15,44 @@ class SchemaConfig ...@@ -15,66 +15,44 @@ class SchemaConfig
/** @var int */ /** @var int */
protected $maxIdentifierLength = 63; protected $maxIdentifierLength = 63;
/** @var string */ /** @var string|null */
protected $name; protected $name;
/** @var mixed[] */ /** @var array<string, mixed> */
protected $defaultTableOptions = []; protected $defaultTableOptions = [];
/** public function hasExplicitForeignKeyIndexes() : bool
* @return bool
*/
public function hasExplicitForeignKeyIndexes()
{ {
return $this->hasExplicitForeignKeyIndexes; return $this->hasExplicitForeignKeyIndexes;
} }
/** public function setExplicitForeignKeyIndexes(bool $flag) : void
* @param bool $flag
*
* @return void
*/
public function setExplicitForeignKeyIndexes($flag)
{ {
$this->hasExplicitForeignKeyIndexes = (bool) $flag; $this->hasExplicitForeignKeyIndexes = $flag;
} }
/** public function setMaxIdentifierLength(int $length) : void
* @param int $length
*
* @return void
*/
public function setMaxIdentifierLength($length)
{ {
$this->maxIdentifierLength = (int) $length; $this->maxIdentifierLength = $length;
} }
/** public function getMaxIdentifierLength() : int
* @return int
*/
public function getMaxIdentifierLength()
{ {
return $this->maxIdentifierLength; return $this->maxIdentifierLength;
} }
/** /**
* Gets the default namespace of schema objects. * Gets the default namespace of schema objects.
*
* @return string
*/ */
public function getName() public function getName() : ?string
{ {
return $this->name; return $this->name;
} }
/** /**
* Sets the default namespace name of schema objects. * 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; $this->name = $name;
} }
...@@ -83,19 +61,17 @@ class SchemaConfig ...@@ -83,19 +61,17 @@ class SchemaConfig
* Gets the default options that are passed to Table instances created with * Gets the default options that are passed to Table instances created with
* Schema#createTable(). * Schema#createTable().
* *
* @return mixed[] * @return array<string, mixed>
*/ */
public function getDefaultTableOptions() public function getDefaultTableOptions() : array
{ {
return $this->defaultTableOptions; return $this->defaultTableOptions;
} }
/** /**
* @param mixed[] $defaultTableOptions * @param array<string, mixed> $defaultTableOptions
*
* @return void
*/ */
public function setDefaultTableOptions(array $defaultTableOptions) public function setDefaultTableOptions(array $defaultTableOptions) : void
{ {
$this->defaultTableOptions = $defaultTableOptions; $this->defaultTableOptions = $defaultTableOptions;
} }
......
...@@ -18,58 +18,58 @@ class SchemaDiff ...@@ -18,58 +18,58 @@ class SchemaDiff
/** /**
* All added namespaces. * All added namespaces.
* *
* @var string[] * @var array<string, string>
*/ */
public $newNamespaces = []; public $newNamespaces = [];
/** /**
* All removed namespaces. * All removed namespaces.
* *
* @var string[] * @var array<string, string>
*/ */
public $removedNamespaces = []; public $removedNamespaces = [];
/** /**
* All added tables. * All added tables.
* *
* @var Table[] * @var array<string, Table>
*/ */
public $newTables = []; public $newTables = [];
/** /**
* All changed tables. * All changed tables.
* *
* @var TableDiff[] * @var array<string, TableDiff>
*/ */
public $changedTables = []; public $changedTables = [];
/** /**
* All removed tables. * All removed tables.
* *
* @var Table[] * @var array<string, Table>
*/ */
public $removedTables = []; public $removedTables = [];
/** @var Sequence[] */ /** @var array<int, Sequence> */
public $newSequences = []; public $newSequences = [];
/** @var Sequence[] */ /** @var array<int, Sequence> */
public $changedSequences = []; public $changedSequences = [];
/** @var Sequence[] */ /** @var array<int, Sequence> */
public $removedSequences = []; public $removedSequences = [];
/** @var ForeignKeyConstraint[] */ /** @var array<string|int, ForeignKeyConstraint> */
public $orphanedForeignKeys = []; public $orphanedForeignKeys = [];
/** /**
* Constructs an SchemaDiff object. * Constructs an SchemaDiff object.
* *
* @param Table[] $newTables * @param array<string, Table> $newTables
* @param TableDiff[] $changedTables * @param array<string, TableDiff> $changedTables
* @param Table[] $removedTables * @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->newTables = $newTables;
$this->changedTables = $changedTables; $this->changedTables = $changedTables;
...@@ -86,27 +86,25 @@ class SchemaDiff ...@@ -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. * 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 $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); return $this->_toSql($platform, false);
} }
/** /**
* @param bool $saveMode * @return array<int, string>
*
* @return string[]
*/ */
protected function _toSql(AbstractPlatform $platform, $saveMode = false) protected function _toSql(AbstractPlatform $platform, bool $saveMode = false) : array
{ {
$sql = []; $sql = [];
......
...@@ -22,13 +22,7 @@ class Sequence extends AbstractAsset ...@@ -22,13 +22,7 @@ class Sequence extends AbstractAsset
/** @var int|null */ /** @var int|null */
protected $cache = null; protected $cache = null;
/** public function __construct(string $name, int $allocationSize = 1, int $initialValue = 1, ?int $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)
{ {
$this->_setName($name); $this->_setName($name);
$this->setAllocationSize($allocationSize); $this->setAllocationSize($allocationSize);
...@@ -36,60 +30,36 @@ class Sequence extends AbstractAsset ...@@ -36,60 +30,36 @@ class Sequence extends AbstractAsset
$this->cache = $cache; $this->cache = $cache;
} }
/** public function getAllocationSize() : int
* @return int
*/
public function getAllocationSize()
{ {
return $this->allocationSize; return $this->allocationSize;
} }
/** public function getInitialValue() : int
* @return int
*/
public function getInitialValue()
{ {
return $this->initialValue; return $this->initialValue;
} }
/** public function getCache() : ?int
* @return int|null
*/
public function getCache()
{ {
return $this->cache; return $this->cache;
} }
/** public function setAllocationSize(int $allocationSize) : self
* @param int $allocationSize
*
* @return \Doctrine\DBAL\Schema\Sequence
*/
public function setAllocationSize($allocationSize)
{ {
$this->allocationSize = (int) $allocationSize ?: 1; $this->allocationSize = $allocationSize;
return $this; return $this;
} }
/** public function setInitialValue(int $initialValue) : self
* @param int $initialValue
*
* @return \Doctrine\DBAL\Schema\Sequence
*/
public function setInitialValue($initialValue)
{ {
$this->initialValue = (int) $initialValue ?: 1; $this->initialValue = $initialValue;
return $this; return $this;
} }
/** public function setCache(int $cache) : self
* @param int $cache
*
* @return \Doctrine\DBAL\Schema\Sequence
*/
public function setCache($cache)
{ {
$this->cache = $cache; $this->cache = $cache;
...@@ -101,10 +71,8 @@ class Sequence extends AbstractAsset ...@@ -101,10 +71,8 @@ class Sequence extends AbstractAsset
* *
* This is used inside the comparator to not report sequences as missing, * This is used inside the comparator to not report sequences as missing,
* when the "from" schema implicitly creates the sequences. * when the "from" schema implicitly creates the sequences.
*
* @return bool
*/ */
public function isAutoIncrementsFor(Table $table) public function isAutoIncrementsFor(Table $table) : bool
{ {
$primaryKey = $table->getPrimaryKey(); $primaryKey = $table->getPrimaryKey();
...@@ -131,10 +99,7 @@ class Sequence extends AbstractAsset ...@@ -131,10 +99,7 @@ class Sequence extends AbstractAsset
return $tableSequenceName === $sequenceName; return $tableSequenceName === $sequenceName;
} }
/** public function visit(Visitor $visitor) : void
* @return void
*/
public function visit(Visitor $visitor)
{ {
$visitor->acceptSequence($this); $visitor->acceptSequence($this);
} }
......
...@@ -4,7 +4,6 @@ declare(strict_types=1); ...@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Schema; namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\StringType;
...@@ -16,6 +15,7 @@ use function array_reverse; ...@@ -16,6 +15,7 @@ use function array_reverse;
use function array_values; use function array_values;
use function count; use function count;
use function file_exists; use function file_exists;
use function is_string;
use function preg_match; use function preg_match;
use function preg_match_all; use function preg_match_all;
use function preg_quote; use function preg_quote;
...@@ -37,7 +37,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -37,7 +37,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropDatabase($database) public function dropDatabase(string $database) : void
{ {
if (! file_exists($database)) { if (! file_exists($database)) {
return; return;
...@@ -49,7 +49,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -49,7 +49,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createDatabase($database) public function createDatabase(string $database) : void
{ {
$params = $this->_conn->getParams(); $params = $this->_conn->getParams();
$driver = $params['driver']; $driver = $params['driver'];
...@@ -65,7 +65,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -65,7 +65,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function renameTable($name, $newName) public function renameTable(string $name, string $newName) : void
{ {
$tableDiff = new TableDiff($name); $tableDiff = new TableDiff($name);
$tableDiff->fromTable = $this->listTableDetails($name); $tableDiff->fromTable = $this->listTableDetails($name);
...@@ -76,9 +76,12 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -76,9 +76,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@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; $tableDiff->addedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff); $this->alterTable($tableDiff);
...@@ -87,9 +90,12 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -87,9 +90,12 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@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; $tableDiff->changedForeignKeys[] = $foreignKey;
$this->alterTable($tableDiff); $this->alterTable($tableDiff);
...@@ -98,10 +104,17 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -98,10 +104,17 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropForeignKey($foreignKey, $table) public function dropForeignKey($foreignKey, $table) : void
{ {
$tableDiff = $this->getTableDiffForAlterForeignKey($table); $table = $this->ensureTable($table);
$tableDiff->removedForeignKeys[] = $foreignKey;
$tableDiff = $this->getTableDiffForAlterForeignKey($table);
if (is_string($foreignKey)) {
$tableDiff->removedForeignKeys[] = $table->getForeignKey($foreignKey);
} else {
$tableDiff->removedForeignKeys[] = $foreignKey;
}
$this->alterTable($tableDiff); $this->alterTable($tableDiff);
} }
...@@ -109,7 +122,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -109,7 +122,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function listTableForeignKeys($table, $database = null) public function listTableForeignKeys(string $table, ?string $database = null) : array
{ {
if ($database === null) { if ($database === null) {
$database = $this->_conn->getDatabase(); $database = $this->_conn->getDatabase();
...@@ -154,7 +167,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -154,7 +167,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableDefinition($table) protected function _getPortableTableDefinition(array $table) : string
{ {
return $table['name']; return $table['name'];
} }
...@@ -228,18 +241,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -228,18 +241,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
* *
* @deprecated * @deprecated
*/ */
protected function _getPortableTableIndexDefinition($tableIndex) protected function _getPortableTableColumnList(string $table, string $database, array $tableColumns) : array
{
return [
'name' => $tableIndex['name'],
'unique' => (bool) $tableIndex['unique'],
];
}
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnList($table, $database, $tableColumns)
{ {
$list = parent::_getPortableTableColumnList($table, $database, $tableColumns); $list = parent::_getPortableTableColumnList($table, $database, $tableColumns);
...@@ -297,7 +299,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -297,7 +299,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableColumnDefinition($tableColumn) protected function _getPortableTableColumnDefinition(array $tableColumn) : Column
{ {
preg_match('/^([^()]*)\\s*(\\(((\\d+)(,\\s*(\\d+))?)\\))?/', $tableColumn['type'], $matches); preg_match('/^([^()]*)\\s*(\\(((\\d+)(,\\s*(\\d+))?)\\))?/', $tableColumn['type'], $matches);
...@@ -359,7 +361,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -359,7 +361,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableViewDefinition($view) protected function _getPortableViewDefinition(array $view) : View
{ {
return new View($view['name'], $view['sql']); return new View($view['name'], $view['sql']);
} }
...@@ -367,7 +369,7 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -367,7 +369,7 @@ class SqliteSchemaManager extends AbstractSchemaManager
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
protected function _getPortableTableForeignKeysList($tableForeignKeys) protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array
{ {
$list = []; $list = [];
foreach ($tableForeignKeys as $value) { foreach ($tableForeignKeys as $value) {
...@@ -415,31 +417,26 @@ class SqliteSchemaManager extends AbstractSchemaManager ...@@ -415,31 +417,26 @@ class SqliteSchemaManager extends AbstractSchemaManager
return $result; return $result;
} }
/** private function getTableDiffForAlterForeignKey(Table $table) : TableDiff
* @param Table|string $table
*
* @return TableDiff
*
* @throws DBALException
*/
private function getTableDiffForAlterForeignKey($table)
{ {
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 = new TableDiff($table->getName());
$tableDiff->fromTable = $table; $tableDiff->fromTable = $table;
return $tableDiff; 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 private function parseColumnCollationFromSQL(string $column, string $sql) : ?string
{ {
$pattern = '{(?:\W' . preg_quote($column) . '\W|\W' . preg_quote($this->_platform->quoteSingleIdentifier($column)) $pattern = '{(?:\W' . preg_quote($column) . '\W|\W' . preg_quote($this->_platform->quoteSingleIdentifier($column))
...@@ -505,10 +502,7 @@ SQL ...@@ -505,10 +502,7 @@ SQL
) ?: null; ) ?: null;
} }
/** public function listTableDetails(string $tableName) : Table
* @param string $tableName
*/
public function listTableDetails($tableName) : Table
{ {
$table = parent::listTableDetails($tableName); $table = parent::listTableDetails($tableName);
......
...@@ -21,9 +21,9 @@ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer ...@@ -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) { foreach ($sql as $s) {
try { try {
...@@ -34,9 +34,9 @@ abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer ...@@ -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) { foreach ($sql as $s) {
$this->conn->exec($s); $this->conn->exec($s);
......
...@@ -15,60 +15,48 @@ interface SchemaSynchronizer ...@@ -15,60 +15,48 @@ interface SchemaSynchronizer
/** /**
* Gets the SQL statements that can be executed to create the schema. * 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. * Gets the SQL Statements to update given schema with the underlying db.
* *
* @param bool $noDrops * @return array<int, string>
*
* @return 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. * Gets the SQL Statements to drop the given schema from underlying db.
* *
* @return string[] * @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. * 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. * Creates the Schema.
*
* @return void
*/ */
public function createSchema(Schema $createSchema); public function createSchema(Schema $createSchema) : void;
/** /**
* Updates the Schema to new schema version. * 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. * 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. * Drops all assets from the underlying db.
*
* @return void
*/ */
public function dropAllSchema(); public function dropAllSchema() : void;
} }
...@@ -28,7 +28,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -28,7 +28,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCreateSchema(Schema $createSchema) public function getCreateSchema(Schema $createSchema) : array
{ {
return $createSchema->toSql($this->platform); return $createSchema->toSql($this->platform);
} }
...@@ -36,7 +36,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -36,7 +36,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getUpdateSchema(Schema $toSchema, $noDrops = false) public function getUpdateSchema(Schema $toSchema, bool $noDrops = false) : array
{ {
$comparator = new Comparator(); $comparator = new Comparator();
$sm = $this->conn->getSchemaManager(); $sm = $this->conn->getSchemaManager();
...@@ -54,7 +54,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -54,7 +54,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDropSchema(Schema $dropSchema) public function getDropSchema(Schema $dropSchema) : array
{ {
$visitor = new DropSchemaSqlCollector($this->platform); $visitor = new DropSchemaSqlCollector($this->platform);
$sm = $this->conn->getSchemaManager(); $sm = $this->conn->getSchemaManager();
...@@ -114,7 +114,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -114,7 +114,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getDropAllSchema() public function getDropAllSchema() : array
{ {
$sm = $this->conn->getSchemaManager(); $sm = $this->conn->getSchemaManager();
$visitor = new DropSchemaSqlCollector($this->platform); $visitor = new DropSchemaSqlCollector($this->platform);
...@@ -128,7 +128,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -128,7 +128,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function createSchema(Schema $createSchema) public function createSchema(Schema $createSchema) : void
{ {
$this->processSql($this->getCreateSchema($createSchema)); $this->processSql($this->getCreateSchema($createSchema));
} }
...@@ -136,7 +136,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -136,7 +136,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function updateSchema(Schema $toSchema, $noDrops = false) public function updateSchema(Schema $toSchema, bool $noDrops = false) : void
{ {
$this->processSql($this->getUpdateSchema($toSchema, $noDrops)); $this->processSql($this->getUpdateSchema($toSchema, $noDrops));
} }
...@@ -144,7 +144,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -144,7 +144,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropSchema(Schema $dropSchema) public function dropSchema(Schema $dropSchema) : void
{ {
$this->processSqlSafely($this->getDropSchema($dropSchema)); $this->processSqlSafely($this->getDropSchema($dropSchema));
} }
...@@ -152,7 +152,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer ...@@ -152,7 +152,7 @@ class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function dropAllSchema() public function dropAllSchema() : void
{ {
$this->processSql($this->getDropAllSchema()); $this->processSql($this->getDropAllSchema());
} }
......
This diff is collapsed.
...@@ -14,83 +14,83 @@ class TableDiff ...@@ -14,83 +14,83 @@ class TableDiff
/** @var string */ /** @var string */
public $name = null; public $name = null;
/** @var string|false */ /** @var string|null */
public $newName = false; public $newName = null;
/** /**
* All added fields. * All added fields.
* *
* @var Column[] * @var array<string, Column>
*/ */
public $addedColumns; public $addedColumns;
/** /**
* All changed fields. * All changed fields.
* *
* @var ColumnDiff[] * @var array<string, ColumnDiff>
*/ */
public $changedColumns = []; public $changedColumns = [];
/** /**
* All removed fields. * All removed fields.
* *
* @var Column[] * @var array<string, Column>
*/ */
public $removedColumns = []; public $removedColumns = [];
/** /**
* Columns that are only renamed from key to column instance name. * Columns that are only renamed from key to column instance name.
* *
* @var Column[] * @var array<string, Column>
*/ */
public $renamedColumns = []; public $renamedColumns = [];
/** /**
* All added indexes. * All added indexes.
* *
* @var Index[] * @var array<string, Index>
*/ */
public $addedIndexes = []; public $addedIndexes = [];
/** /**
* All changed indexes. * All changed indexes.
* *
* @var Index[] * @var array<string, Index>
*/ */
public $changedIndexes = []; public $changedIndexes = [];
/** /**
* All removed indexes * All removed indexes
* *
* @var Index[] * @var array<string, Index>
*/ */
public $removedIndexes = []; public $removedIndexes = [];
/** /**
* Indexes that are only renamed but are identical otherwise. * Indexes that are only renamed but are identical otherwise.
* *
* @var Index[] * @var array<string, Index>
*/ */
public $renamedIndexes = []; public $renamedIndexes = [];
/** /**
* All added foreign key definitions * All added foreign key definitions
* *
* @var ForeignKeyConstraint[] * @var array<int, ForeignKeyConstraint>
*/ */
public $addedForeignKeys = []; public $addedForeignKeys = [];
/** /**
* All changed foreign keys * All changed foreign keys
* *
* @var ForeignKeyConstraint[] * @var array<int, ForeignKeyConstraint>
*/ */
public $changedForeignKeys = []; public $changedForeignKeys = [];
/** /**
* All removed foreign keys * All removed foreign keys
* *
* @var ForeignKeyConstraint[]|string[] * @var array<int, ForeignKeyConstraint>
*/ */
public $removedForeignKeys = []; public $removedForeignKeys = [];
...@@ -100,22 +100,21 @@ class TableDiff ...@@ -100,22 +100,21 @@ class TableDiff
/** /**
* Constructs an TableDiff object. * Constructs an TableDiff object.
* *
* @param string $tableName * @param array<string, Column> $addedColumns
* @param Column[] $addedColumns * @param array<string, ColumnDiff> $changedColumns
* @param ColumnDiff[] $changedColumns * @param array<string, Column> $removedColumns
* @param Column[] $removedColumns * @param array<string, Index> $addedIndexes
* @param Index[] $addedIndexes * @param array<string, Index> $changedIndexes
* @param Index[] $changedIndexes * @param array<string, Index> $removedIndexes
* @param Index[] $removedIndexes
*/ */
public function __construct( public function __construct(
$tableName, string $tableName,
$addedColumns = [], array $addedColumns = [],
$changedColumns = [], array $changedColumns = [],
$removedColumns = [], array $removedColumns = [],
$addedIndexes = [], array $addedIndexes = [],
$changedIndexes = [], array $changedIndexes = [],
$removedIndexes = [], array $removedIndexes = [],
?Table $fromTable = null ?Table $fromTable = null
) { ) {
$this->name = $tableName; $this->name = $tableName;
...@@ -130,23 +129,18 @@ class TableDiff ...@@ -130,23 +129,18 @@ class TableDiff
/** /**
* @param AbstractPlatform $platform The platform to use for retrieving this table diff's name. * @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( return new Identifier(
$this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name $this->fromTable instanceof Table ? $this->fromTable->getQuotedName($platform) : $this->name
); );
} }
/** public function getNewName() : ?Identifier
* @return Identifier|false
*/
public function getNewName()
{ {
if ($this->newName === false) { if ($this->newName === null) {
return false; return null;
} }
return new Identifier($this->newName); return new Identifier($this->newName);
......
...@@ -16,34 +16,31 @@ class UniqueConstraint extends AbstractAsset implements Constraint ...@@ -16,34 +16,31 @@ class UniqueConstraint extends AbstractAsset implements Constraint
{ {
/** /**
* Asset identifier instances of the column names the unique constraint is associated with. * Asset identifier instances of the column names the unique constraint is associated with.
* array($columnName => Identifier)
* *
* @var Identifier[] * @var array<string, Identifier>
*/ */
protected $columns = []; protected $columns = [];
/** /**
* Platform specific flags * Platform specific flags
* array($flagName => true)
* *
* @var true[] * @var array<string, true>
*/ */
protected $flags = []; protected $flags = [];
/** /**
* Platform specific options * Platform specific options
* *
* @var mixed[] * @var array<string, mixed>
*/ */
private $options = []; private $options = [];
/** /**
* @param string $indexName * @param array<string> $columns
* @param string[] $columns * @param array<string> $flags
* @param string[] $flags * @param array<string, mixed> $options
* @param 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); $this->_setName($indexName);
...@@ -61,7 +58,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint ...@@ -61,7 +58,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getColumns() public function getColumns() : array
{ {
return array_keys($this->columns); return array_keys($this->columns);
} }
...@@ -69,7 +66,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint ...@@ -69,7 +66,7 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getQuotedColumns(AbstractPlatform $platform) public function getQuotedColumns(AbstractPlatform $platform) : array
{ {
$columns = []; $columns = [];
...@@ -81,9 +78,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint ...@@ -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()); return array_map([$this, 'trimQuotes'], $this->getColumns());
} }
...@@ -91,9 +88,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint ...@@ -91,9 +88,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/** /**
* Returns platform specific flags for unique 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); return array_keys($this->flags);
} }
...@@ -101,13 +98,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint ...@@ -101,13 +98,9 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/** /**
* Adds flag for a unique constraint that translates to platform specific handling. * Adds flag for a unique constraint that translates to platform specific handling.
* *
* @param string $flag
*
* @return self
*
* @example $uniqueConstraint->addFlag('CLUSTERED') * @example $uniqueConstraint->addFlag('CLUSTERED')
*/ */
public function addFlag($flag) public function addFlag(string $flag) : self
{ {
$this->flags[strtolower($flag)] = true; $this->flags[strtolower($flag)] = true;
...@@ -116,52 +109,37 @@ class UniqueConstraint extends AbstractAsset implements Constraint ...@@ -116,52 +109,37 @@ class UniqueConstraint extends AbstractAsset implements Constraint
/** /**
* Does this unique constraint have a specific flag? * 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)]); return isset($this->flags[strtolower($flag)]);
} }
/** /**
* Removes a flag. * Removes a flag.
*
* @param string $flag
*
* @return void
*/ */
public function removeFlag($flag) public function removeFlag(string $flag) : void
{ {
unset($this->flags[strtolower($flag)]); unset($this->flags[strtolower($flag)]);
} }
/** public function hasOption(string $name) : bool
* @param string $name
*
* @return bool
*/
public function hasOption($name)
{ {
return isset($this->options[strtolower($name)]); return isset($this->options[strtolower($name)]);
} }
/** /**
* @param string $name
*
* @return mixed * @return mixed
*/ */
public function getOption($name) public function getOption(string $name)
{ {
return $this->options[strtolower($name)]; return $this->options[strtolower($name)];
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function getOptions() public function getOptions() : array
{ {
return $this->options; return $this->options;
} }
......
...@@ -12,20 +12,13 @@ class View extends AbstractAsset ...@@ -12,20 +12,13 @@ class View extends AbstractAsset
/** @var string */ /** @var string */
private $sql; private $sql;
/** public function __construct(string $name, string $sql)
* @param string $name
* @param string $sql
*/
public function __construct($name, $sql)
{ {
$this->_setName($name); $this->_setName($name);
$this->sql = $sql; $this->sql = $sql;
} }
/** public function getSql() : string
* @return string
*/
public function getSql()
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -16,34 +16,34 @@ use Doctrine\DBAL\Schema\Table; ...@@ -16,34 +16,34 @@ use Doctrine\DBAL\Schema\Table;
*/ */
class AbstractVisitor implements Visitor, NamespaceVisitor class AbstractVisitor implements Visitor, NamespaceVisitor
{ {
public function acceptSchema(Schema $schema) public function acceptSchema(Schema $schema) : void
{ {
} }
/** /**
* {@inheritdoc} * {@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; ...@@ -12,16 +12,16 @@ use function array_merge;
class CreateSchemaSqlCollector extends AbstractVisitor class CreateSchemaSqlCollector extends AbstractVisitor
{ {
/** @var string[] */ /** @var array<string> */
private $createNamespaceQueries = []; private $createNamespaceQueries = [];
/** @var string[] */ /** @var array<string> */
private $createTableQueries = []; private $createTableQueries = [];
/** @var string[] */ /** @var array<string> */
private $createSequenceQueries = []; private $createSequenceQueries = [];
/** @var string[] */ /** @var array<string> */
private $createFkConstraintQueries = []; private $createFkConstraintQueries = [];
/** @var AbstractPlatform */ /** @var AbstractPlatform */
...@@ -35,7 +35,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor ...@@ -35,7 +35,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptNamespace($namespaceName) public function acceptNamespace(string $namespaceName) : void
{ {
if (! $this->platform->supportsSchemas()) { if (! $this->platform->supportsSchemas()) {
return; return;
...@@ -47,7 +47,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor ...@@ -47,7 +47,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptTable(Table $table) public function acceptTable(Table $table) : void
{ {
$this->createTableQueries = array_merge($this->createTableQueries, $this->platform->getCreateTableSQL($table)); $this->createTableQueries = array_merge($this->createTableQueries, $this->platform->getCreateTableSQL($table));
} }
...@@ -55,7 +55,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor ...@@ -55,7 +55,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{ {
if (! $this->platform->supportsForeignKeyConstraints()) { if (! $this->platform->supportsForeignKeyConstraints()) {
return; return;
...@@ -67,15 +67,12 @@ class CreateSchemaSqlCollector extends AbstractVisitor ...@@ -67,15 +67,12 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptSequence(Sequence $sequence) public function acceptSequence(Sequence $sequence) : void
{ {
$this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence); $this->createSequenceQueries[] = $this->platform->getCreateSequenceSQL($sequence);
} }
/** public function resetQueries() : void
* @return void
*/
public function resetQueries()
{ {
$this->createNamespaceQueries = []; $this->createNamespaceQueries = [];
$this->createTableQueries = []; $this->createTableQueries = [];
...@@ -86,9 +83,9 @@ class CreateSchemaSqlCollector extends AbstractVisitor ...@@ -86,9 +83,9 @@ class CreateSchemaSqlCollector extends AbstractVisitor
/** /**
* Gets all queries collected so far. * Gets all queries collected so far.
* *
* @return string[] * @return array<string>
*/ */
public function getQueries() public function getQueries() : array
{ {
return array_merge( return array_merge(
$this->createNamespaceQueries, $this->createNamespaceQueries,
......
...@@ -38,7 +38,7 @@ class DropSchemaSqlCollector extends AbstractVisitor ...@@ -38,7 +38,7 @@ class DropSchemaSqlCollector extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptTable(Table $table) public function acceptTable(Table $table) : void
{ {
$this->tables->attach($table); $this->tables->attach($table);
} }
...@@ -46,7 +46,7 @@ class DropSchemaSqlCollector extends AbstractVisitor ...@@ -46,7 +46,7 @@ class DropSchemaSqlCollector extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{ {
if (strlen($fkConstraint->getName()) === 0) { if (strlen($fkConstraint->getName()) === 0) {
throw NamedForeignKeyRequired::new($localTable, $fkConstraint); throw NamedForeignKeyRequired::new($localTable, $fkConstraint);
...@@ -58,15 +58,12 @@ class DropSchemaSqlCollector extends AbstractVisitor ...@@ -58,15 +58,12 @@ class DropSchemaSqlCollector extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptSequence(Sequence $sequence) public function acceptSequence(Sequence $sequence) : void
{ {
$this->sequences->attach($sequence); $this->sequences->attach($sequence);
} }
/** public function clearQueries() : void
* @return void
*/
public function clearQueries()
{ {
$this->constraints = new SplObjectStorage(); $this->constraints = new SplObjectStorage();
$this->sequences = new SplObjectStorage(); $this->sequences = new SplObjectStorage();
...@@ -74,9 +71,9 @@ class DropSchemaSqlCollector extends AbstractVisitor ...@@ -74,9 +71,9 @@ class DropSchemaSqlCollector extends AbstractVisitor
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getQueries() public function getQueries() : array
{ {
$sql = []; $sql = [];
......
...@@ -23,7 +23,7 @@ class Graphviz extends AbstractVisitor ...@@ -23,7 +23,7 @@ class Graphviz extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void
{ {
$this->output .= $this->createNodeRelation( $this->output .= $this->createNodeRelation(
$fkConstraint->getLocalTableName() . ':col' . current($fkConstraint->getLocalColumns()) . ':se', $fkConstraint->getLocalTableName() . ':col' . current($fkConstraint->getLocalColumns()) . ':se',
...@@ -39,7 +39,7 @@ class Graphviz extends AbstractVisitor ...@@ -39,7 +39,7 @@ class Graphviz extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptSchema(Schema $schema) public function acceptSchema(Schema $schema) : void
{ {
$this->output = 'digraph "' . $schema->getName() . '" {' . "\n"; $this->output = 'digraph "' . $schema->getName() . '" {' . "\n";
$this->output .= 'splines = true;' . "\n"; $this->output .= 'splines = true;' . "\n";
...@@ -52,7 +52,7 @@ class Graphviz extends AbstractVisitor ...@@ -52,7 +52,7 @@ class Graphviz extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptTable(Table $table) public function acceptTable(Table $table) : void
{ {
$this->output .= $this->createNode( $this->output .= $this->createNode(
$table->getName(), $table->getName(),
...@@ -63,10 +63,7 @@ class Graphviz extends AbstractVisitor ...@@ -63,10 +63,7 @@ class Graphviz extends AbstractVisitor
); );
} }
/** private function createTableLabel(Table $table) : string
* @return string
*/
private function createTableLabel(Table $table)
{ {
// Start the table // Start the table
$label = '<<TABLE CELLSPACING="0" BORDER="1" ALIGN="LEFT">'; $label = '<<TABLE CELLSPACING="0" BORDER="1" ALIGN="LEFT">';
...@@ -99,12 +96,9 @@ class Graphviz extends AbstractVisitor ...@@ -99,12 +96,9 @@ class Graphviz extends AbstractVisitor
} }
/** /**
* @param string $name * @param array<string, string> $options
* @param string[] $options
*
* @return string
*/ */
private function createNode($name, $options) private function createNode(string $name, array $options) : string
{ {
$node = $name . ' ['; $node = $name . ' [';
foreach ($options as $key => $value) { foreach ($options as $key => $value) {
...@@ -116,13 +110,9 @@ class Graphviz extends AbstractVisitor ...@@ -116,13 +110,9 @@ class Graphviz extends AbstractVisitor
} }
/** /**
* @param string $node1 * @param array<string, string> $options
* @param string $node2
* @param string[] $options
*
* @return string
*/ */
private function createNodeRelation($node1, $node2, $options) private function createNodeRelation(string $node1, string $node2, array $options) : string
{ {
$relation = $node1 . ' -> ' . $node2 . ' ['; $relation = $node1 . ' -> ' . $node2 . ' [';
foreach ($options as $key => $value) { foreach ($options as $key => $value) {
...@@ -135,10 +125,8 @@ class Graphviz extends AbstractVisitor ...@@ -135,10 +125,8 @@ class Graphviz extends AbstractVisitor
/** /**
* Get Graphviz Output * Get Graphviz Output
*
* @return string
*/ */
public function getOutput() public function getOutput() : string
{ {
return $this->output . '}'; return $this->output . '}';
} }
...@@ -150,12 +138,8 @@ class Graphviz extends AbstractVisitor ...@@ -150,12 +138,8 @@ class Graphviz extends AbstractVisitor
* and execute: * and execute:
* *
* neato -Tpng -o er.png er.dot * 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()); file_put_contents($filename, $this->getOutput());
} }
......
...@@ -14,5 +14,5 @@ interface NamespaceVisitor ...@@ -14,5 +14,5 @@ interface NamespaceVisitor
* *
* @param string $namespaceName The schema namespace name to accept. * @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 ...@@ -28,7 +28,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptSchema(Schema $schema) public function acceptSchema(Schema $schema) : void
{ {
$this->schema = $schema; $this->schema = $schema;
} }
...@@ -36,7 +36,7 @@ class RemoveNamespacedAssets extends AbstractVisitor ...@@ -36,7 +36,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptTable(Table $table) public function acceptTable(Table $table) : void
{ {
if ($table->isInDefaultNamespace($this->schema->getName())) { if ($table->isInDefaultNamespace($this->schema->getName())) {
return; return;
...@@ -48,7 +48,7 @@ class RemoveNamespacedAssets extends AbstractVisitor ...@@ -48,7 +48,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function acceptSequence(Sequence $sequence) public function acceptSequence(Sequence $sequence) : void
{ {
if ($sequence->isInDefaultNamespace($this->schema->getName())) { if ($sequence->isInDefaultNamespace($this->schema->getName())) {
return; return;
...@@ -60,7 +60,7 @@ class RemoveNamespacedAssets extends AbstractVisitor ...@@ -60,7 +60,7 @@ class RemoveNamespacedAssets extends AbstractVisitor
/** /**
* {@inheritdoc} * {@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 // The table may already be deleted in a previous
// RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that // RemoveNamespacedAssets#acceptTable call. Removing Foreign keys that
......
...@@ -16,33 +16,15 @@ use Doctrine\DBAL\Schema\Table; ...@@ -16,33 +16,15 @@ use Doctrine\DBAL\Schema\Table;
*/ */
interface Visitor interface Visitor
{ {
/** public function acceptSchema(Schema $schema) : void;
* @return void
*/ public function acceptTable(Table $table) : void;
public function acceptSchema(Schema $schema);
public function acceptColumn(Table $table, Column $column) : void;
/**
* @return void public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void;
*/
public function acceptTable(Table $table); public function acceptIndex(Table $table, Index $index) : void;
/** public function acceptSequence(Sequence $sequence) : void;
* @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);
} }
...@@ -41,4 +41,9 @@ class DriverTest extends AbstractDriverTest ...@@ -41,4 +41,9 @@ class DriverTest extends AbstractDriverTest
{ {
return new Driver(); return new Driver();
} }
protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return '';
}
} }
...@@ -156,7 +156,7 @@ class NamedParametersTest extends DbalFunctionalTestCase ...@@ -156,7 +156,7 @@ class NamedParametersTest extends DbalFunctionalTestCase
{ {
parent::setUp(); parent::setUp();
if ($this->connection->getSchemaManager()->tablesExist('ddc1372_foobar')) { if ($this->connection->getSchemaManager()->tableExists('ddc1372_foobar')) {
return; return;
} }
......
...@@ -39,7 +39,7 @@ class ComparatorTest extends DbalFunctionalTestCase ...@@ -39,7 +39,7 @@ class ComparatorTest extends DbalFunctionalTestCase
$onlineTable = $this->schemaManager->listTableDetails('default_value'); $onlineTable = $this->schemaManager->listTableDetails('default_value');
self::assertFalse($this->comparator->diffTable($table, $onlineTable)); self::assertNull($this->comparator->diffTable($table, $onlineTable));
} }
/** /**
......
...@@ -237,7 +237,7 @@ SQL; ...@@ -237,7 +237,7 @@ SQL;
if ($expectedComparatorDiff) { if ($expectedComparatorDiff) {
self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff)); self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff));
} else { } else {
self::assertFalse($diff); self::assertNull($diff);
} }
} }
......
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