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