From 695f2fc44fbd1702ed37cea21f51248837d6f489 Mon Sep 17 00:00:00 2001 From: "Jonathan H. Wage" Date: Tue, 28 May 2019 11:11:44 -0500 Subject: [PATCH] Add proper types to Doctrine\DBAL\Schema namespace. --- UPGRADE.md | 12 + .../SchemaCreateTableColumnEventArgs.php | 9 +- .../DBAL/Event/SchemaCreateTableEventArgs.php | 7 +- .../DBAL/Exception/DatabaseRequired.php | 21 + .../DBAL/Id/TableGeneratorSchemaVisitor.php | 12 +- .../DBAL/Platforms/AbstractPlatform.php | 10 +- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 2 +- lib/Doctrine/DBAL/Platforms/MySqlPlatform.php | 4 +- .../DBAL/Platforms/OraclePlatform.php | 4 +- .../DBAL/Platforms/PostgreSqlPlatform.php | 2 +- .../DBAL/Platforms/SQLAnywherePlatform.php | 2 +- .../DBAL/Platforms/SQLServerPlatform.php | 2 +- .../DBAL/Platforms/SqlitePlatform.php | 6 +- lib/Doctrine/DBAL/Schema/AbstractAsset.php | 60 +-- .../DBAL/Schema/AbstractSchemaManager.php | 410 +++++++----------- lib/Doctrine/DBAL/Schema/Column.php | 18 +- lib/Doctrine/DBAL/Schema/ColumnDiff.php | 19 +- lib/Doctrine/DBAL/Schema/Comparator.php | 51 +-- lib/Doctrine/DBAL/Schema/Constraint.php | 18 +- lib/Doctrine/DBAL/Schema/DB2SchemaManager.php | 10 +- .../DBAL/Schema/ForeignKeyConstraint.php | 111 ++--- lib/Doctrine/DBAL/Schema/Identifier.php | 2 +- lib/Doctrine/DBAL/Schema/Index.php | 119 ++--- .../DBAL/Schema/MySqlSchemaManager.php | 19 +- .../DBAL/Schema/OracleSchemaManager.php | 51 +-- .../DBAL/Schema/PostgreSqlSchemaManager.php | 40 +- .../DBAL/Schema/SQLAnywhereSchemaManager.php | 32 +- .../DBAL/Schema/SQLServerSchemaManager.php | 35 +- lib/Doctrine/DBAL/Schema/Schema.php | 147 ++----- lib/Doctrine/DBAL/Schema/SchemaConfig.php | 52 +-- lib/Doctrine/DBAL/Schema/SchemaDiff.php | 40 +- lib/Doctrine/DBAL/Schema/Sequence.php | 57 +-- .../DBAL/Schema/SqliteSchemaManager.php | 89 ++-- .../AbstractSchemaSynchronizer.php | 8 +- .../Synchronizer/SchemaSynchronizer.php | 34 +- .../SingleDatabaseSynchronizer.php | 16 +- lib/Doctrine/DBAL/Schema/Table.php | 278 ++++-------- lib/Doctrine/DBAL/Schema/TableDiff.php | 66 ++- lib/Doctrine/DBAL/Schema/UniqueConstraint.php | 62 +-- lib/Doctrine/DBAL/Schema/View.php | 11 +- .../DBAL/Schema/Visitor/AbstractVisitor.php | 14 +- .../Visitor/CreateSchemaSqlCollector.php | 25 +- .../Schema/Visitor/DropSchemaSqlCollector.php | 15 +- lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php | 36 +- .../DBAL/Schema/Visitor/NamespaceVisitor.php | 2 +- .../Schema/Visitor/RemoveNamespacedAssets.php | 8 +- lib/Doctrine/DBAL/Schema/Visitor/Visitor.php | 40 +- .../SQLAzureFederationsSynchronizer.php | 16 +- .../SQLAzure/Schema/MultiTenantVisitor.php | 12 +- .../Driver/PDOSqlite/DriverTest.php | 5 + .../DBAL/Functional/NamedParametersTest.php | 2 +- .../DBAL/Functional/Schema/ComparatorTest.php | 2 +- .../Schema/MySqlSchemaManagerTest.php | 25 +- .../Schema/PostgreSqlSchemaManagerTest.php | 6 +- .../SchemaManagerFunctionalTestCase.php | 4 +- .../Schema/SqliteSchemaManagerTest.php | 2 +- .../DBAL/Functional/Ticket/DBAL202Test.php | 2 +- .../DBAL/Functional/Ticket/DBAL510Test.php | 2 +- .../Tests/DBAL/Schema/ComparatorTest.php | 6 +- .../Tests/DBAL/Schema/TableDiffTest.php | 2 +- 60 files changed, 786 insertions(+), 1388 deletions(-) create mode 100644 lib/Doctrine/DBAL/Exception/DatabaseRequired.php diff --git a/UPGRADE.md b/UPGRADE.md index e63fefae05d..8d16265fcdc 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,17 @@ # Upgrade to 3.0 +## BC BREAK: Changes in the `Doctrine\DBAL\Schema` API + +- Method `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableViewDefinition()` no longer optionally returns false. It will always return a `Doctrine\DBAL\Schema\View` instance. +- 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. diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php index 312892daa7b..f4e70e0ff89 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableColumnEventArgs.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Table; -use function array_merge; use function is_array; /** @@ -24,7 +23,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs /** @var AbstractPlatform */ private $platform; - /** @var string[] */ + /** @var array */ private $sql = []; public function __construct(Column $column, Table $table, AbstractPlatform $platform) @@ -66,7 +65,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); + foreach ($sql as $query) { + $this->sql[] = $query; + } } else { $this->sql[] = $sql; } @@ -75,7 +76,7 @@ public function addSql($sql) } /** - * @return string[] + * @return array */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php index 7c05d1e8df1..5046add54c3 100644 --- a/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php +++ b/lib/Doctrine/DBAL/Event/SchemaCreateTableEventArgs.php @@ -6,7 +6,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Table; -use function array_merge; use function is_array; /** @@ -81,7 +80,9 @@ public function getPlatform() public function addSql($sql) { if (is_array($sql)) { - $this->sql = array_merge($this->sql, $sql); + foreach ($sql as $query) { + $this->sql[] = $query; + } } else { $this->sql[] = $sql; } @@ -90,7 +91,7 @@ public function addSql($sql) } /** - * @return string[] + * @return array */ public function getSql() { diff --git a/lib/Doctrine/DBAL/Exception/DatabaseRequired.php b/lib/Doctrine/DBAL/Exception/DatabaseRequired.php new file mode 100644 index 00000000000..b2110e5339e --- /dev/null +++ b/lib/Doctrine/DBAL/Exception/DatabaseRequired.php @@ -0,0 +1,21 @@ +createTable($this->generatorTableName); $table->addColumn('sequence_name', 'string'); @@ -39,35 +39,35 @@ public function acceptSchema(Schema $schema) /** * {@inheritdoc} */ - public function acceptTable(Table $table) + public function acceptTable(Table $table) : void { } /** * {@inheritdoc} */ - public function acceptColumn(Table $table, Column $column) + public function acceptColumn(Table $table, Column $column) : void { } /** * {@inheritdoc} */ - public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) + public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void { } /** * {@inheritdoc} */ - public function acceptIndex(Table $table, Index $index) + public function acceptIndex(Table $table, Index $index) : void { } /** * {@inheritdoc} */ - public function acceptSequence(Sequence $sequence) + public function acceptSequence(Sequence $sequence) : void { } } diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 285a91cdbb1..8444ee2d17c 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1274,7 +1274,7 @@ public function getDropForeignKeySQL($foreignKey, $table) : string * Returns the SQL statement(s) to create a table with the specified name, columns and constraints * on this platform. * - * @return string[] The sequence of SQL statements. + * @return array The sequence of SQL statements. * * @throws DBALException */ @@ -1406,7 +1406,7 @@ public function getInlineColumnCommentSQL(?string $comment) : string * @param mixed[][] $columns * @param mixed[] $options * - * @return string[] + * @return array */ protected function _getCreateTableSQL(string $tableName, array $columns, array $options = []) : array { @@ -1436,7 +1436,7 @@ protected function _getCreateTableSQL(string $tableName, array $columns, array $ } $query .= ')'; - $sql[] = $query; + $sql = [$query]; if (isset($options['foreignKeys'])) { foreach ((array) $options['foreignKeys'] as $definition) { @@ -1642,7 +1642,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) * * This method returns an array of SQL statements, since some platforms need several statements. * - * @return string[] + * @return array * * @throws DBALException If not supported on this platform. */ @@ -1791,7 +1791,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) : array $sql = []; $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $tableName = $newName->getQuotedName($this); } else { $tableName = $diff->getName($this)->getQuotedName($this); diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 5b0b47792f6..174ea7eabc8 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -597,7 +597,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $sql[] = sprintf( 'RENAME TABLE %s TO %s', $diff->getName($this)->getQuotedName($this), diff --git a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php index 47946f42008..4e94a8c0030 100644 --- a/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php @@ -512,7 +512,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $queryParts = []; $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $queryParts[] = 'RENAME TO ' . $newName->getQuotedName($this); } @@ -817,7 +817,7 @@ protected function getPostAlterTableRenameIndexForeignKeySQL(TableDiff $diff) : $sql = []; $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $tableName = $newName->getQuotedName($this); } else { $tableName = $diff->getName($this)->getQuotedName($this); diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 9214eedb828..21e0906d8a9 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -461,7 +461,7 @@ public function getDropViewSQL(string $name) : string } /** - * @return string[] + * @return array */ public function getCreateAutoincrementSql(string $name, string $table, int $start = 1) : array { @@ -854,7 +854,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $sql[] = sprintf( 'ALTER TABLE %s RENAME TO %s', $diff->getName($this)->getQuotedName($this), diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index b250195fd34..b4fb8554776 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -591,7 +591,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $sql[] = sprintf( 'ALTER TABLE %s RENAME TO %s', $diff->getName($this)->getQuotedName($this), diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index b3f370cc4e4..4b1d949a3e6 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -190,7 +190,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . $this->getAlterTableRenameTableClause($newName); } diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 03b843a9801..68ee541e23d 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -574,7 +574,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'"; /** diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 49943c1556d..c741506e048 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -671,7 +671,7 @@ protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) : array $sql = []; $tableName = $diff->getNewName(); - if ($tableName === false) { + if ($tableName === null) { $tableName = $diff->getName($this); } @@ -898,7 +898,7 @@ public function getAlterTableSQL(TableDiff $diff) : array $newName = $diff->getNewName(); - if ($newName !== false) { + if ($newName !== null) { $sql[] = sprintf( 'ALTER TABLE %s RENAME TO %s', $newTable->getQuotedName($this), @@ -980,7 +980,7 @@ private function getSimpleAlterTableSQL(TableDiff $diff) } if (! $this->onSchemaAlterTable($diff, $tableSql)) { - if ($diff->newName !== false) { + if ($diff->newName !== null) { $newTable = new Identifier($diff->newName); $sql[] = 'ALTER TABLE ' . $table->getQuotedName($this) . ' RENAME TO ' . $newTable->getQuotedName($this); } diff --git a/lib/Doctrine/DBAL/Schema/AbstractAsset.php b/lib/Doctrine/DBAL/Schema/AbstractAsset.php index cfa469d9de7..6afec63d20d 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractAsset.php +++ b/lib/Doctrine/DBAL/Schema/AbstractAsset.php @@ -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 @@ protected function _setName($name) /** * 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 @@ public function isInDefaultNamespace($defaultNamespaceName) * 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 @@ public function getNamespaceName() /** * 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 @@ public function getShortestName($defaultNamespaceName) * * 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 @@ public function getFullQualifiedName($defaultNamespaceName) /** * 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 @@ public function getName() /** * 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 @@ public function getQuotedName(AbstractPlatform $platform) * 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 $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)); diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 2a71f88dde8..64edf7d39d3 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -10,12 +10,14 @@ use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs; use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception\DatabaseRequired; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\Exception\NotSupported; use Throwable; use function array_filter; use function array_intersect; use function array_map; +use function array_shift; use function array_values; use function assert; use function call_user_func_array; @@ -57,10 +59,8 @@ public function __construct(Connection $conn, ?AbstractPlatform $platform = null /** * Returns the associated platform. - * - * @return AbstractPlatform */ - public function getDatabasePlatform() + public function getDatabasePlatform() : AbstractPlatform { return $this->_platform; } @@ -97,9 +97,9 @@ public function tryMethod() /** * Lists the available databases for this connection. * - * @return string[] + * @return array */ - public function listDatabases() + public function listDatabases() : array { $sql = $this->_platform->getListDatabasesSQL(); @@ -111,9 +111,9 @@ public function listDatabases() /** * Returns a list of all namespaces in the current database. * - * @return string[] + * @return array */ - public function listNamespaceNames() + public function listNamespaceNames() : array { $sql = $this->_platform->getListNamespacesSQL(); @@ -125,15 +125,15 @@ public function listNamespaceNames() /** * Lists the available sequences for this connection. * - * @param string|null $database - * - * @return Sequence[] + * @return array */ - public function listSequences($database = null) + public function listSequences(?string $database = null) : array { - if ($database === null) { - $database = $this->_conn->getDatabase(); - } + $database = $this->ensureDatabase( + $database ?? $this->_conn->getDatabase(), + __METHOD__ + ); + $sql = $this->_platform->getListSequencesSQL($database); $sequences = $this->_conn->fetchAll($sql); @@ -151,16 +151,14 @@ public function listSequences($database = null) * of a table. We're a RDBMS specifies more details these are held * in the platformDetails array. * - * @param string $table The name of the table. - * @param string|null $database - * - * @return Column[] + * @return array */ - public function listTableColumns($table, $database = null) + public function listTableColumns(string $table, ?string $database = null) : array { - if (! $database) { - $database = $this->_conn->getDatabase(); - } + $database = $this->ensureDatabase( + $database ?? $this->_conn->getDatabase(), + __METHOD__ + ); $sql = $this->_platform->getListTableColumnsSQL($table, $database); @@ -174,11 +172,9 @@ public function listTableColumns($table, $database = null) * * Keys of the portable indexes list are all lower-cased. * - * @param string $table The name of the table. - * - * @return Index[] + * @return array */ - public function listTableIndexes($table) + public function listTableIndexes(string $table) : array { $sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase()); @@ -190,23 +186,26 @@ public function listTableIndexes($table) /** * Returns true if all the given tables exist. * - * @param string|string[] $tableNames - * - * @return bool + * @param array $tableNames */ - public function tablesExist($tableNames) + public function tablesExist(array $tableNames) : bool { - $tableNames = array_map('strtolower', (array) $tableNames); + $tableNames = array_map('strtolower', $tableNames); return count($tableNames) === count(array_intersect($tableNames, array_map('strtolower', $this->listTableNames()))); } + public function tableExists(string $tableName) : bool + { + return $this->tablesExist([$tableName]); + } + /** * Returns a list of all tables in the current database. * - * @return string[] + * @return array */ - public function listTableNames() + public function listTableNames() : array { $sql = $this->_platform->getListTablesSQL(); @@ -220,11 +219,11 @@ public function listTableNames() * Filters asset names if they are configured to return only a subset of all * the found elements. * - * @param mixed[] $assetNames + * @param array $assetNames * - * @return mixed[] + * @return array */ - protected function filterAssetNames($assetNames) + protected function filterAssetNames(array $assetNames) { $filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter(); if (! $filter) { @@ -237,9 +236,9 @@ protected function filterAssetNames($assetNames) /** * Lists the tables for this connection. * - * @return Table[] + * @return array */ - public function listTables() + public function listTables() : array { $tableNames = $this->listTableNames(); @@ -251,12 +250,7 @@ public function listTables() return $tables; } - /** - * @param string $tableName - * - * @return Table - */ - public function listTableDetails($tableName) + public function listTableDetails(string $tableName) : Table { $columns = $this->listTableColumns($tableName); $foreignKeys = []; @@ -273,13 +267,17 @@ public function listTableDetails($tableName) /** * Lists the views this connection has. * - * @return View[] + * @return array */ - public function listViews() + public function listViews() : array { - $database = $this->_conn->getDatabase(); - $sql = $this->_platform->getListViewsSQL($database); - $views = $this->_conn->fetchAll($sql); + $database = $this->ensureDatabase( + $this->_conn->getDatabase(), + __METHOD__ + ); + + $sql = $this->_platform->getListViewsSQL($database); + $views = $this->_conn->fetchAll($sql); return $this->_getPortableViewsList($views); } @@ -287,12 +285,9 @@ public function listViews() /** * Lists the foreign keys for the given table. * - * @param string $table The name of the table. - * @param string|null $database - * - * @return ForeignKeyConstraint[] + * @return array */ - public function listTableForeignKeys($table, $database = null) + public function listTableForeignKeys(string $table, ?string $database = null) : array { if ($database === null) { $database = $this->_conn->getDatabase(); @@ -309,24 +304,16 @@ public function listTableForeignKeys($table, $database = null) * Drops a database. * * NOTE: You can not drop the database this SchemaManager is currently connected to. - * - * @param string $database The name of the database to drop. - * - * @return void */ - public function dropDatabase($database) + public function dropDatabase(string $database) : void { $this->_execSql($this->_platform->getDropDatabaseSQL($database)); } /** * Drops the given table. - * - * @param string $tableName The name of the table to drop. - * - * @return void */ - public function dropTable($tableName) + public function dropTable(string $tableName) : void { $this->_execSql($this->_platform->getDropTableSQL($tableName)); } @@ -336,10 +323,8 @@ public function dropTable($tableName) * * @param Index|string $index The name of the index. * @param Table|string $table The name of the table. - * - * @return void */ - public function dropIndex($index, $table) + public function dropIndex($index, $table) : void { if ($index instanceof Index) { $index = $index->getQuotedName($this->_platform); @@ -352,10 +337,8 @@ public function dropIndex($index, $table) * Drops the constraint from the given table. * * @param Table|string $table The name of the table. - * - * @return void */ - public function dropConstraint(Constraint $constraint, $table) + public function dropConstraint(Constraint $constraint, $table) : void { $this->_execSql($this->_platform->getDropConstraintSQL($constraint, $table)); } @@ -365,34 +348,24 @@ public function dropConstraint(Constraint $constraint, $table) * * @param ForeignKeyConstraint|string $foreignKey The name of the foreign key. * @param Table|string $table The name of the table with the foreign key. - * - * @return void */ - public function dropForeignKey($foreignKey, $table) + public function dropForeignKey($foreignKey, $table) : void { $this->_execSql($this->_platform->getDropForeignKeySQL($foreignKey, $table)); } /** * Drops a sequence with a given name. - * - * @param string $name The name of the sequence to drop. - * - * @return void */ - public function dropSequence($name) + public function dropSequence(string $name) : void { $this->_execSql($this->_platform->getDropSequenceSQL($name)); } /** * Drops a view. - * - * @param string $name The name of the view. - * - * @return void */ - public function dropView($name) + public function dropView(string $name) : void { $this->_execSql($this->_platform->getDropViewSQL($name)); } @@ -401,22 +374,16 @@ public function dropView($name) /** * Creates a new database. - * - * @param string $database The name of the database to create. - * - * @return void */ - public function createDatabase($database) + public function createDatabase(string $database) : void { $this->_execSql($this->_platform->getCreateDatabaseSQL($database)); } /** * Creates a new table. - * - * @return void */ - public function createTable(Table $table) + public function createTable(Table $table) : void { $createFlags = AbstractPlatform::CREATE_INDEXES|AbstractPlatform::CREATE_FOREIGNKEYS; $this->_execSql($this->_platform->getCreateTableSQL($table, $createFlags)); @@ -425,13 +392,9 @@ public function createTable(Table $table) /** * Creates a new sequence. * - * @param Sequence $sequence - * - * @return void - * * @throws ConnectionException If something fails at database level. */ - public function createSequence($sequence) + public function createSequence(Sequence $sequence) : void { $this->_execSql($this->_platform->getCreateSequenceSQL($sequence)); } @@ -440,10 +403,8 @@ public function createSequence($sequence) * Creates a constraint on a table. * * @param Table|string $table - * - * @return void */ - public function createConstraint(Constraint $constraint, $table) + public function createConstraint(Constraint $constraint, $table) : void { $this->_execSql($this->_platform->getCreateConstraintSQL($constraint, $table)); } @@ -452,10 +413,8 @@ public function createConstraint(Constraint $constraint, $table) * Creates a new index on a table. * * @param Table|string $table The name of the table on which the index is to be created. - * - * @return void */ - public function createIndex(Index $index, $table) + public function createIndex(Index $index, $table) : void { $this->_execSql($this->_platform->getCreateIndexSQL($index, $table)); } @@ -465,20 +424,16 @@ public function createIndex(Index $index, $table) * * @param ForeignKeyConstraint $foreignKey The ForeignKey instance. * @param Table|string $table The name of the table on which the foreign key is to be created. - * - * @return void */ - public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) + public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) : void { $this->_execSql($this->_platform->getCreateForeignKeySQL($foreignKey, $table)); } /** * Creates a new view. - * - * @return void */ - public function createView(View $view) + public function createView(View $view) : void { $this->_execSql($this->_platform->getCreateViewSQL($view->getQuotedName($this->_platform), $view->getSql())); } @@ -492,10 +447,8 @@ public function createView(View $view) * @see createConstraint() * * @param Table|string $table - * - * @return void */ - public function dropAndCreateConstraint(Constraint $constraint, $table) + public function dropAndCreateConstraint(Constraint $constraint, $table) : void { $this->tryMethod('dropConstraint', $constraint, $table); $this->createConstraint($constraint, $table); @@ -505,10 +458,8 @@ public function dropAndCreateConstraint(Constraint $constraint, $table) * Drops and creates a new index on a table. * * @param Table|string $table The name of the table on which the index is to be created. - * - * @return void */ - public function dropAndCreateIndex(Index $index, $table) + public function dropAndCreateIndex(Index $index, $table) : void { $this->tryMethod('dropIndex', $index->getQuotedName($this->_platform), $table); $this->createIndex($index, $table); @@ -519,10 +470,8 @@ public function dropAndCreateIndex(Index $index, $table) * * @param ForeignKeyConstraint $foreignKey An associative array that defines properties of the foreign key to be created. * @param Table|string $table The name of the table on which the foreign key is to be created. - * - * @return void */ - public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) + public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) : void { $this->tryMethod('dropForeignKey', $foreignKey, $table); $this->createForeignKey($foreignKey, $table); @@ -531,11 +480,9 @@ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table /** * Drops and create a new sequence. * - * @return void - * * @throws ConnectionException If something fails at database level. */ - public function dropAndCreateSequence(Sequence $sequence) + public function dropAndCreateSequence(Sequence $sequence) : void { $this->tryMethod('dropSequence', $sequence->getQuotedName($this->_platform)); $this->createSequence($sequence); @@ -543,10 +490,8 @@ public function dropAndCreateSequence(Sequence $sequence) /** * Drops and creates a new table. - * - * @return void */ - public function dropAndCreateTable(Table $table) + public function dropAndCreateTable(Table $table) : void { $this->tryMethod('dropTable', $table->getQuotedName($this->_platform)); $this->createTable($table); @@ -554,12 +499,8 @@ public function dropAndCreateTable(Table $table) /** * Drops and creates a new database. - * - * @param string $database The name of the database to create. - * - * @return void */ - public function dropAndCreateDatabase($database) + public function dropAndCreateDatabase(string $database) : void { $this->tryMethod('dropDatabase', $database); $this->createDatabase($database); @@ -567,10 +508,8 @@ public function dropAndCreateDatabase($database) /** * Drops and creates a new view. - * - * @return void */ - public function dropAndCreateView(View $view) + public function dropAndCreateView(View $view) : void { $this->tryMethod('dropView', $view->getQuotedName($this->_platform)); $this->createView($view); @@ -580,10 +519,8 @@ public function dropAndCreateView(View $view) /** * Alters an existing tables schema. - * - * @return void */ - public function alterTable(TableDiff $tableDiff) + public function alterTable(TableDiff $tableDiff) : void { $queries = $this->_platform->getAlterTableSQL($tableDiff); @@ -598,13 +535,8 @@ public function alterTable(TableDiff $tableDiff) /** * Renames a given table to another name. - * - * @param string $name The current name of the table. - * @param string $newName The new name of the table. - * - * @return void */ - public function renameTable($name, $newName) + public function renameTable(string $name, string $newName) : void { $tableDiff = new TableDiff($name); $tableDiff->newName = $newName; @@ -617,11 +549,11 @@ public function renameTable($name, $newName) */ /** - * @param mixed[] $databases + * @param array $databases * - * @return string[] + * @return array */ - protected function _getPortableDatabasesList($databases) + protected function _getPortableDatabasesList(array $databases) : array { $list = []; foreach ($databases as $value) { @@ -640,11 +572,11 @@ protected function _getPortableDatabasesList($databases) /** * Converts a list of namespace names from the native DBMS data definition to a portable Doctrine definition. * - * @param mixed[][] $namespaces The list of namespace names in the native DBMS data definition. + * @param array> $namespaces The list of namespace names in the native DBMS data definition. * - * @return string[] + * @return array */ - protected function getPortableNamespacesList(array $namespaces) + protected function getPortableNamespacesList(array $namespaces) : array { $namespacesList = []; @@ -656,64 +588,29 @@ protected function getPortableNamespacesList(array $namespaces) } /** - * @param mixed $database - * - * @return mixed + * @param array $database */ - protected function _getPortableDatabaseDefinition($database) + protected function _getPortableDatabaseDefinition(array $database) : string { - return $database; + return array_shift($database); } /** * Converts a namespace definition from the native DBMS data definition to a portable Doctrine definition. * - * @param mixed[] $namespace The native DBMS namespace definition. - * - * @return mixed - */ - protected function getPortableNamespaceDefinition(array $namespace) - { - return $namespace; - } - - /** - * @param mixed[][] $functions - * - * @return mixed[][] - */ - protected function _getPortableFunctionsList($functions) - { - $list = []; - foreach ($functions as $value) { - $value = $this->_getPortableFunctionDefinition($value); - - if (! $value) { - continue; - } - - $list[] = $value; - } - - return $list; - } - - /** - * @param mixed[] $function - * - * @return mixed + * @param array $namespace The native DBMS namespace definition. */ - protected function _getPortableFunctionDefinition($function) + protected function getPortableNamespaceDefinition(array $namespace) : string { - return $function; + return array_shift($namespace); } /** - * @param mixed[][] $triggers + * @param array> $triggers * - * @return mixed[][] + * @return array */ - protected function _getPortableTriggersList($triggers) + protected function _getPortableTriggersList(array $triggers) { $list = []; foreach ($triggers as $value) { @@ -730,21 +627,19 @@ protected function _getPortableTriggersList($triggers) } /** - * @param mixed[] $trigger - * - * @return mixed + * @param array $trigger */ - protected function _getPortableTriggerDefinition($trigger) + protected function _getPortableTriggerDefinition(array $trigger) : string { - return $trigger; + return array_shift($trigger); } /** - * @param mixed[][] $sequences + * @param array> $sequences * - * @return Sequence[] + * @return array */ - protected function _getPortableSequencesList($sequences) + protected function _getPortableSequencesList(array $sequences) : array { $list = []; @@ -756,13 +651,11 @@ protected function _getPortableSequencesList($sequences) } /** - * @param mixed[] $sequence - * - * @return Sequence + * @param array $sequence * * @throws DBALException */ - protected function _getPortableSequenceDefinition($sequence) + protected function _getPortableSequenceDefinition(array $sequence) : Sequence { throw NotSupported::new('Sequences'); } @@ -772,13 +665,11 @@ protected function _getPortableSequenceDefinition($sequence) * * The name of the created column instance however is kept in its case. * - * @param string $table The name of the table. - * @param string $database - * @param mixed[][] $tableColumns + * @param array> $tableColumns * - * @return Column[] + * @return array */ - protected function _getPortableTableColumnList($table, $database, $tableColumns) + protected function _getPortableTableColumnList(string $table, string $database, array $tableColumns) : array { $eventManager = $this->_platform->getEventManager(); @@ -813,18 +704,16 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) /** * Gets Table Column Definition. * - * @param mixed[] $tableColumn - * - * @return Column + * @param array $tableColumn */ - abstract protected function _getPortableTableColumnDefinition($tableColumn); + abstract protected function _getPortableTableColumnDefinition(array $tableColumn) : Column; /** * Aggregates and groups the index results according to the required data result. * - * @param mixed[][] $tableIndexRows + * @param array> $tableIndexRows * - * @return Index[] + * @return array */ protected function _getPortableTableIndexesList(array $tableIndexRows, string $tableName) : array { @@ -889,11 +778,11 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t } /** - * @param mixed[][] $tables + * @param array> $tables * - * @return string[] + * @return array */ - protected function _getPortableTablesList($tables) + protected function _getPortableTablesList(array $tables) : array { $list = []; foreach ($tables as $value) { @@ -910,21 +799,19 @@ protected function _getPortableTablesList($tables) } /** - * @param mixed $table - * - * @return string + * @param array $table */ - protected function _getPortableTableDefinition($table) + protected function _getPortableTableDefinition(array $table) : string { - return $table; + return array_shift($table); } /** - * @param mixed[][] $users + * @param array> $users * - * @return string[][] + * @return array> */ - protected function _getPortableUsersList($users) + protected function _getPortableUsersList(array $users) : array { $list = []; foreach ($users as $value) { @@ -941,53 +828,46 @@ protected function _getPortableUsersList($users) } /** - * @param string[] $user + * @param array $user * - * @return string[] + * @return array */ - protected function _getPortableUserDefinition($user) + protected function _getPortableUserDefinition(array $user) : array { return $user; } /** - * @param mixed[][] $views + * @param array> $views * - * @return View[] + * @return array */ - protected function _getPortableViewsList($views) + protected function _getPortableViewsList(array $views) : array { $list = []; foreach ($views as $value) { - $view = $this->_getPortableViewDefinition($value); - - if (! $view) { - continue; - } - - $viewName = strtolower($view->getQuotedName($this->_platform)); - $list[$viewName] = $view; + $view = $this->_getPortableViewDefinition($value); + $name = strtolower($view->getQuotedName($this->_platform)); + $list[$name] = $view; } return $list; } /** - * @param mixed[] $view - * - * @return View|false + * @param array $view */ - protected function _getPortableViewDefinition($view) + protected function _getPortableViewDefinition(array $view) : View { - return false; + throw NotSupported::new('Views'); } /** - * @param mixed[][] $tableForeignKeys + * @param array> $tableForeignKeys * - * @return ForeignKeyConstraint[] + * @return array */ - protected function _getPortableTableForeignKeysList($tableForeignKeys) + protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array { $list = []; @@ -999,21 +879,17 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) } /** - * @param mixed $tableForeignKey - * - * @return ForeignKeyConstraint + * @param array $tableForeignKey */ - protected function _getPortableTableForeignKeyDefinition($tableForeignKey) + protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint { - return $tableForeignKey; + throw NotSupported::new('ForeignKey'); } /** - * @param string[]|string $sql - * - * @return void + * @param array|string $sql */ - protected function _execSql($sql) + protected function _execSql($sql) : void { foreach ((array) $sql as $query) { $this->_conn->executeUpdate($query); @@ -1022,10 +898,8 @@ protected function _execSql($sql) /** * Creates a schema instance for the current database. - * - * @return Schema */ - public function createSchema() + public function createSchema() : Schema { $namespaces = []; @@ -1046,10 +920,8 @@ public function createSchema() /** * Creates the configuration for this schema. - * - * @return SchemaConfig */ - public function createSchemaConfig() + public function createSchemaConfig() : SchemaConfig { $schemaConfig = new SchemaConfig(); $schemaConfig->setMaxIdentifierLength($this->_platform->getMaxIdentifierLength()); @@ -1081,9 +953,9 @@ public function createSchemaConfig() * For databases that don't support subschema/namespaces this method * returns the name of the currently connected database. * - * @return string[] + * @return array */ - public function getSchemaSearchPaths() + public function getSchemaSearchPaths() : array { return [$this->_conn->getDatabase()]; } @@ -1104,4 +976,16 @@ final protected function extractDoctrineTypeFromComment(?string &$comment) : ?st return $match[2]; } + + /** + * @throws DatabaseRequired + */ + private function ensureDatabase(?string $database, string $methodName) : string + { + if ($database === null) { + throw DatabaseRequired::new($methodName); + } + + return $database; + } } diff --git a/lib/Doctrine/DBAL/Schema/Column.php b/lib/Doctrine/DBAL/Schema/Column.php index fa45a953f0b..928f0485ec2 100644 --- a/lib/Doctrine/DBAL/Schema/Column.php +++ b/lib/Doctrine/DBAL/Schema/Column.php @@ -43,7 +43,7 @@ class Column extends AbstractAsset /** @var bool */ protected $_autoincrement = false; - /** @var mixed[] */ + /** @var array */ protected $_platformOptions = []; /** @var string|null */ @@ -52,13 +52,13 @@ class Column extends AbstractAsset /** @var string|null */ protected $_comment; - /** @var mixed[] */ + /** @var array */ protected $_customSchemaOptions = []; /** * Creates a new Column. * - * @param mixed[] $options + * @param array $options */ public function __construct(string $name, Type $type, array $options = []) { @@ -68,7 +68,7 @@ public function __construct(string $name, Type $type, array $options = []) } /** - * @param mixed[] $options + * @param array $options */ public function setOptions(array $options) : self { @@ -154,7 +154,7 @@ public function setDefault($default) : self } /** - * @param mixed[] $platformOptions + * @param array $platformOptions */ public function setPlatformOptions(array $platformOptions) : self { @@ -224,7 +224,7 @@ public function getDefault() } /** - * @return mixed[] + * @return array */ public function getPlatformOptions() : array { @@ -297,7 +297,7 @@ public function getCustomSchemaOption(string $name) } /** - * @param mixed[] $customSchemaOptions + * @param array $customSchemaOptions */ public function setCustomSchemaOptions(array $customSchemaOptions) : self { @@ -307,7 +307,7 @@ public function setCustomSchemaOptions(array $customSchemaOptions) : self } /** - * @return mixed[] + * @return array */ public function getCustomSchemaOptions() : array { @@ -315,7 +315,7 @@ public function getCustomSchemaOptions() : array } /** - * @return mixed[] + * @return array */ public function toArray() : array { diff --git a/lib/Doctrine/DBAL/Schema/ColumnDiff.php b/lib/Doctrine/DBAL/Schema/ColumnDiff.php index f98f9108bfd..14c0d78ed92 100644 --- a/lib/Doctrine/DBAL/Schema/ColumnDiff.php +++ b/lib/Doctrine/DBAL/Schema/ColumnDiff.php @@ -17,17 +17,16 @@ class ColumnDiff /** @var Column */ public $column; - /** @var string[] */ + /** @var array */ public $changedProperties = []; /** @var Column|null */ public $fromColumn; /** - * @param string $oldColumnName - * @param string[] $changedProperties + * @param array $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 @@ public function __construct($oldColumnName, Column $column, array $changedProper $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(); diff --git a/lib/Doctrine/DBAL/Schema/Comparator.php b/lib/Doctrine/DBAL/Schema/Comparator.php index 4fbab28e03f..6f090cf39b2 100644 --- a/lib/Doctrine/DBAL/Schema/Comparator.php +++ b/lib/Doctrine/DBAL/Schema/Comparator.php @@ -20,10 +20,7 @@ */ class Comparator { - /** - * @return SchemaDiff - */ - public static function compareSchemas(Schema $fromSchema, Schema $toSchema) + public static function compareSchemas(Schema $fromSchema, Schema $toSchema) : SchemaDiff { $c = new self(); @@ -36,10 +33,8 @@ public static function compareSchemas(Schema $fromSchema, Schema $toSchema) * 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; @@ -68,7 +63,7 @@ public function compare(Schema $fromSchema, Schema $toSchema) $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; } } @@ -151,13 +146,7 @@ public function compare(Schema $fromSchema, Schema $toSchema) 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)) { @@ -168,10 +157,7 @@ private function isAutoIncrementSequenceInSchema($schema, $sequence) 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; @@ -184,10 +170,8 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2) * 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()); @@ -293,16 +277,14 @@ public function diffTable(Table $table1, Table $table2) $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) { @@ -339,10 +321,8 @@ private function detectColumnRenamings(TableDiff $tableDifferences) /** * 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 = []; @@ -383,10 +363,7 @@ private function detectIndexRenamings(TableDiff $tableDifferences) } } - /** - * @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; @@ -413,9 +390,9 @@ public function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint * If there are differences this method returns $field2, otherwise the * boolean false. * - * @return string[] + * @return array */ - public function diffColumn(Column $column1, Column $column2) + public function diffColumn(Column $column1, Column $column2) : array { $properties1 = $column1->toArray(); $properties2 = $column2->toArray(); @@ -497,10 +474,8 @@ public function diffColumn(Column $column1, Column $column2) * * 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)); } diff --git a/lib/Doctrine/DBAL/Schema/Constraint.php b/lib/Doctrine/DBAL/Schema/Constraint.php index c939a06e33e..2c167b9de67 100644 --- a/lib/Doctrine/DBAL/Schema/Constraint.php +++ b/lib/Doctrine/DBAL/Schema/Constraint.php @@ -11,23 +11,17 @@ */ 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 */ - public function getColumns(); + public function getColumns() : array; /** * Returns the quoted representation of the column names @@ -39,7 +33,7 @@ public function getColumns(); * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return string[] + * @return array */ - public function getQuotedColumns(AbstractPlatform $platform); + public function getQuotedColumns(AbstractPlatform $platform) : array; } diff --git a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php index 78cd8d8133f..7cfbf474530 100644 --- a/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/DB2SchemaManager.php @@ -42,7 +42,7 @@ public function listTableNames() : array /** * {@inheritdoc} */ - protected function _getPortableTableColumnDefinition($tableColumn) + protected function _getPortableTableColumnDefinition(array $tableColumn) : Column { $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); @@ -104,7 +104,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) /** * {@inheritdoc} */ - protected function _getPortableTablesList($tables) + protected function _getPortableTablesList(array $tables) : array { $tableNames = []; foreach ($tables as $tableRow) { @@ -131,7 +131,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeyDefinition($tableForeignKey) + protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint { return new ForeignKeyConstraint( $tableForeignKey['local_columns'], @@ -145,7 +145,7 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeysList($tableForeignKeys) + protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array { $foreignKeys = []; @@ -175,7 +175,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) /** * {@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 diff --git a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php index 3ccd2ede590..6b7844f4b42 100644 --- a/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php +++ b/lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php @@ -27,9 +27,8 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint /** * Asset identifier instances of the referencing table column names the foreign key constraint is associated with. - * array($columnName => Identifier) * - * @var Identifier[] + * @var array */ protected $_localColumnNames; @@ -42,27 +41,26 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint /** * Asset identifier instances of the referenced table column names the foreign key constraint is associated with. - * array($columnName => Identifier) * - * @var Identifier[] + * @var array */ protected $_foreignColumnNames; /** * Options associated with the foreign key constraint. * - * @var mixed[] + * @var array */ protected $_options; /** * Initializes the foreign key constraint. * - * @param string[] $localColumnNames Names of the referencing table columns. - * @param Table|string $foreignTableName Referenced table. - * @param string[] $foreignColumnNames Names of the referenced table columns. - * @param string|null $name Name of the foreign key constraint. - * @param mixed[] $options Options associated with the foreign key constraint. + * @param array $localColumnNames Names of the referencing table columns. + * @param Table|string $foreignTableName Referenced table. + * @param array $foreignColumnNames Names of the referenced table columns. + * @param string|null $name Name of the foreign key constraint. + * @param array $options Options associated with the foreign key constraint. */ public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = []) { @@ -83,9 +81,9 @@ public function __construct(array $localColumnNames, $foreignTableName, array $f } /** - * @param string[] $names + * @param array $names * - * @return Identifier[] + * @return array */ private function createIdentifierMap(array $names) : array { @@ -101,10 +99,8 @@ private function createIdentifierMap(array $names) : array /** * Returns the name of the referencing table * the foreign key constraint is associated with. - * - * @return string */ - public function getLocalTableName() + public function getLocalTableName() : string { return $this->_localTable->getName(); } @@ -112,20 +108,13 @@ public function getLocalTableName() /** * Sets the Table instance of the referencing table * the foreign key constraint is associated with. - * - * @param Table $table Instance of the referencing table. - * - * @return void */ - public function setLocalTable(Table $table) + public function setLocalTable(Table $table) : void { $this->_localTable = $table; } - /** - * @return Table - */ - public function getLocalTable() + public function getLocalTable() : Table { return $this->_localTable; } @@ -134,9 +123,9 @@ public function getLocalTable() * Returns the names of the referencing table columns * the foreign key constraint is associated with. * - * @return string[] + * @return array */ - public function getLocalColumns() + public function getLocalColumns() : array { return array_keys($this->_localColumnNames); } @@ -151,9 +140,9 @@ public function getLocalColumns() * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return string[] + * @return array */ - public function getQuotedLocalColumns(AbstractPlatform $platform) + public function getQuotedLocalColumns(AbstractPlatform $platform) : array { $columns = []; @@ -167,9 +156,9 @@ public function getQuotedLocalColumns(AbstractPlatform $platform) /** * Returns unquoted representation of local table column names for comparison with other FK * - * @return string[] + * @return array */ - public function getUnquotedLocalColumns() + public function getUnquotedLocalColumns() : array { return array_map([$this, 'trimQuotes'], $this->getLocalColumns()); } @@ -177,9 +166,9 @@ public function getUnquotedLocalColumns() /** * Returns unquoted representation of foreign table column names for comparison with other FK * - * @return string[] + * @return array */ - public function getUnquotedForeignColumns() + public function getUnquotedForeignColumns() : array { return array_map([$this, 'trimQuotes'], $this->getForeignColumns()); } @@ -189,7 +178,7 @@ public function getUnquotedForeignColumns() * * @see getLocalColumns */ - public function getColumns() + public function getColumns() : array { return $this->getLocalColumns(); } @@ -206,9 +195,9 @@ public function getColumns() * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return string[] + * @return array */ - public function getQuotedColumns(AbstractPlatform $platform) + public function getQuotedColumns(AbstractPlatform $platform) : array { return $this->getQuotedLocalColumns($platform); } @@ -216,20 +205,16 @@ public function getQuotedColumns(AbstractPlatform $platform) /** * Returns the name of the referenced table * the foreign key constraint is associated with. - * - * @return string */ - public function getForeignTableName() + public function getForeignTableName() : string { return $this->_foreignTableName->getName(); } /** * Returns the non-schema qualified foreign table name. - * - * @return string */ - public function getUnqualifiedForeignTableName() + public function getUnqualifiedForeignTableName() : string { $name = $this->_foreignTableName->getName(); $position = strrpos($name, '.'); @@ -250,10 +235,8 @@ public function getUnqualifiedForeignTableName() * Otherwise the plain unquoted value as inserted is returned. * * @param AbstractPlatform $platform The platform to use for quotation. - * - * @return string */ - public function getQuotedForeignTableName(AbstractPlatform $platform) + public function getQuotedForeignTableName(AbstractPlatform $platform) : string { return $this->_foreignTableName->getQuotedName($platform); } @@ -262,9 +245,9 @@ public function getQuotedForeignTableName(AbstractPlatform $platform) * Returns the names of the referenced table columns * the foreign key constraint is associated with. * - * @return string[] + * @return array */ - public function getForeignColumns() + public function getForeignColumns() : array { return array_keys($this->_foreignColumnNames); } @@ -279,9 +262,9 @@ public function getForeignColumns() * * @param AbstractPlatform $platform The platform to use for quotation. * - * @return string[] + * @return array */ - public function getQuotedForeignColumns(AbstractPlatform $platform) + public function getQuotedForeignColumns(AbstractPlatform $platform) : array { $columns = []; @@ -295,12 +278,8 @@ public function getQuotedForeignColumns(AbstractPlatform $platform) /** * Returns whether or not a given option * is associated with the foreign key constraint. - * - * @param string $name Name of the option to check. - * - * @return bool */ - public function hasOption($name) + public function hasOption(string $name) : bool { return isset($this->_options[$name]); } @@ -308,11 +287,9 @@ public function hasOption($name) /** * Returns an option associated with the foreign key constraint. * - * @param string $name Name of the option the foreign key constraint is associated with. - * * @return mixed */ - public function getOption($name) + public function getOption(string $name) { return $this->_options[$name]; } @@ -320,9 +297,9 @@ public function getOption($name) /** * Returns the options associated with the foreign key constraint. * - * @return mixed[] + * @return array */ - public function getOptions() + public function getOptions() : array { return $this->_options; } @@ -330,10 +307,8 @@ public function getOptions() /** * Returns the referential action for UPDATE operations * on the referenced table the foreign key constraint is associated with. - * - * @return string|null */ - public function onUpdate() + public function onUpdate() : ?string { return $this->onEvent('onUpdate'); } @@ -341,10 +316,8 @@ public function onUpdate() /** * Returns the referential action for DELETE operations * on the referenced table the foreign key constraint is associated with. - * - * @return string|null */ - public function onDelete() + public function onDelete() : ?string { return $this->onEvent('onDelete'); } @@ -354,10 +327,8 @@ public function onDelete() * on the referenced table the foreign key constraint is associated with. * * @param string $event Name of the database operation/event to return the referential action for. - * - * @return string|null */ - private function onEvent($event) + private function onEvent(string $event) : ?string { if (isset($this->_options[$event])) { $onEvent = strtoupper($this->_options[$event]); @@ -367,7 +338,7 @@ private function onEvent($event) } } - return false; + return null; } /** @@ -377,10 +348,8 @@ private function onEvent($event) * matches one of the given index's columns, `false` otherwise. * * @param Index $index The index to be checked against. - * - * @return bool */ - public function intersectsIndexColumns(Index $index) + public function intersectsIndexColumns(Index $index) : bool { foreach ($index->getColumns() as $indexColumn) { foreach ($this->_localColumnNames as $localColumn) { diff --git a/lib/Doctrine/DBAL/Schema/Identifier.php b/lib/Doctrine/DBAL/Schema/Identifier.php index 276b7824f1a..c3c84a7b62e 100644 --- a/lib/Doctrine/DBAL/Schema/Identifier.php +++ b/lib/Doctrine/DBAL/Schema/Identifier.php @@ -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); diff --git a/lib/Doctrine/DBAL/Schema/Index.php b/lib/Doctrine/DBAL/Schema/Index.php index b895f3e14a8..b450c070315 100644 --- a/lib/Doctrine/DBAL/Schema/Index.php +++ b/lib/Doctrine/DBAL/Schema/Index.php @@ -5,23 +5,20 @@ 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 */ protected $_columns = []; @@ -33,9 +30,8 @@ class Index extends AbstractAsset implements Constraint /** * Platform specific flags for indexes. - * array($flagName => true) * - * @var true[] + * @var array */ 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 */ private $options = []; /** - * @param string $indexName - * @param string[] $columns - * @param bool $isUnique - * @param bool $isPrimary - * @param string[] $flags - * @param mixed[] $options + * @param array $columns + * @param array $flags + * @param array $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 @@ public function __construct($indexName, array $columns, $isUnique = false, $isPr } } - /** - * @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 @@ public function getColumns() /** * {@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 @@ public function getQuotedColumns(AbstractPlatform $platform) } /** - * @return string[] + * @return array */ - 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 @@ public function hasColumnAtPosition($columnName, $pos = 0) /** * Checks if this index exactly spans the given column names in the correct order. * - * @param string[] $columnNames - * - * @return bool + * @param array $columnNames */ - public function spansColumns(array $columnNames) + public function spansColumns(array $columnNames) : bool { $columns = $this->getColumns(); $numberOfColumns = count($columns); @@ -199,10 +165,8 @@ public function spansColumns(array $columnNames) /** * 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 @@ public function isFullfilledBy(Index $other) /** * 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 @@ public function overrules(Index $other) /** * Returns platform specific flags for indexes. * - * @return string[] + * @return array */ - public function getFlags() + public function getFlags() : array { return array_keys($this->_flags); } @@ -271,13 +233,9 @@ public function getFlags() /** * 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 @@ public function addFlag($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)]); } /** * 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 */ - 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; diff --git a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php index 8363bf74c9b..6b47d2cc1e3 100644 --- a/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/MySqlSchemaManager.php @@ -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 @@ protected function _getPortableViewDefinition($view) /** * {@inheritdoc} */ - protected function _getPortableTableDefinition($table) + protected function _getPortableTableDefinition(array $table) : string { return array_shift($table); } @@ -64,7 +64,7 @@ protected function _getPortableTableDefinition($table) /** * {@inheritdoc} */ - protected function _getPortableUserDefinition($user) + protected function _getPortableUserDefinition(array $user) : array { return [ 'user' => $user['User'], @@ -100,7 +100,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t /** * {@inheritdoc} */ - protected function _getPortableDatabaseDefinition($database) + protected function _getPortableDatabaseDefinition(array $database) : string { return $database['Database']; } @@ -108,7 +108,7 @@ protected function _getPortableDatabaseDefinition($database) /** * {@inheritdoc} */ - protected function _getPortableTableColumnDefinition($tableColumn) + protected function _getPortableTableColumnDefinition(array $tableColumn) : Column { $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); @@ -248,7 +248,7 @@ private function getMariaDb1027ColumnDefault(MariaDb1027Platform $platform, ?str /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeysList($tableForeignKeys) + protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array { $list = []; foreach ($tableForeignKeys as $value) { @@ -291,7 +291,10 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) return $result; } - public function listTableDetails($tableName) + /** + * {@inheritdoc} + */ + public function listTableDetails(string $tableName) : Table { $table = parent::listTableDetails($tableName); @@ -315,7 +318,7 @@ public function listTableDetails($tableName) } /** - * @return string[]|true[] + * @return array|array */ private function parseCreateOptions(?string $string) : array { diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 7474e1bc162..7e6813a7b0d 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -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 @@ public function dropDatabase($database) /** * {@inheritdoc} */ - protected function _getPortableViewDefinition($view) + protected function _getPortableViewDefinition(array $view) : View { $view = array_change_key_case($view, CASE_LOWER); @@ -68,7 +68,7 @@ protected function _getPortableViewDefinition($view) /** * {@inheritdoc} */ - protected function _getPortableUserDefinition($user) + protected function _getPortableUserDefinition(array $user) : array { $user = array_change_key_case($user, CASE_LOWER); @@ -80,7 +80,7 @@ protected function _getPortableUserDefinition($user) /** * {@inheritdoc} */ - protected function _getPortableTableDefinition($table) + protected function _getPortableTableDefinition(array $table) : string { $table = array_change_key_case($table, CASE_LOWER); @@ -120,7 +120,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t /** * {@inheritdoc} */ - protected function _getPortableTableColumnDefinition($tableColumn) + protected function _getPortableTableColumnDefinition(array $tableColumn) : Column { $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); @@ -211,7 +211,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeysList($tableForeignKeys) + protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array { $list = []; foreach ($tableForeignKeys as $value) { @@ -254,7 +254,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) /** * {@inheritdoc} */ - protected function _getPortableSequenceDefinition($sequence) + protected function _getPortableSequenceDefinition(array $sequence) : Sequence { $sequence = array_change_key_case($sequence, CASE_LOWER); @@ -268,17 +268,7 @@ protected function _getPortableSequenceDefinition($sequence) /** * {@inheritdoc} */ - 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); @@ -288,12 +278,8 @@ protected function _getPortableDatabaseDefinition($database) /** * {@inheritdoc} */ - 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']; @@ -305,12 +291,7 @@ public function createDatabase($database = null) $this->_conn->executeUpdate($query); } - /** - * @param string $table - * - * @return bool - */ - public function dropAutoincrement($table) + public function dropAutoincrement(string $table) : bool { assert($this->_platform instanceof OraclePlatform); @@ -325,7 +306,7 @@ public function dropAutoincrement($table) /** * {@inheritdoc} */ - public function dropTable($name) + public function dropTable(string $name) : void { $this->tryMethod('dropAutoincrement', $name); @@ -337,12 +318,8 @@ public function dropTable($name) * * 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); @@ -357,10 +334,8 @@ private function getQuotedIdentifierName($identifier) * 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 = << */ private $existingSchemaPaths; /** * Gets all the existing schema names. * - * @return string[] + * @return array */ - 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 @@ public function getSchemaNames() * * This is a PostgreSQL only function. * - * @return string[] + * @return array */ - public function getSchemaSearchPaths() + public function getSchemaSearchPaths() : array { $params = $this->_conn->getParams(); $schema = explode(',', $this->_conn->fetchColumn('SHOW search_path')); @@ -71,9 +71,9 @@ public function getSchemaSearchPaths() * * This is a PostgreSQL only function. * - * @return string[] + * @return array */ - public function getExistingSchemaSearchPaths() + public function getExistingSchemaSearchPaths() : array { if ($this->existingSchemaPaths === null) { $this->determineExistingSchemaSearchPaths(); @@ -86,10 +86,8 @@ public function getExistingSchemaSearchPaths() * 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 @@ public function determineExistingSchemaSearchPaths() /** * {@inheritdoc} */ - public function dropDatabase($database) + public function dropDatabase(string $database) : void { try { parent::dropDatabase($database); @@ -131,7 +129,7 @@ public function dropDatabase($database) /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeyDefinition($tableForeignKey) + protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint { $onUpdate = null; $onDelete = null; @@ -166,7 +164,7 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) /** * {@inheritdoc} */ - protected function _getPortableTriggerDefinition($trigger) + protected function _getPortableTriggerDefinition(array $trigger) : string { return $trigger['trigger_name']; } @@ -174,7 +172,7 @@ protected function _getPortableTriggerDefinition($trigger) /** * {@inheritdoc} */ - protected function _getPortableViewDefinition($view) + protected function _getPortableViewDefinition(array $view) : View { return new View($view['schemaname'] . '.' . $view['viewname'], $view['definition']); } @@ -182,7 +180,7 @@ protected function _getPortableViewDefinition($view) /** * {@inheritdoc} */ - protected function _getPortableUserDefinition($user) + protected function _getPortableUserDefinition(array $user) : array { return [ 'user' => $user['usename'], @@ -193,7 +191,7 @@ protected function _getPortableUserDefinition($user) /** * {@inheritdoc} */ - protected function _getPortableTableDefinition($table) + protected function _getPortableTableDefinition(array $table) : string { $schemas = $this->getExistingSchemaSearchPaths(); $firstSchema = array_shift($schemas); @@ -248,7 +246,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t /** * {@inheritdoc} */ - protected function _getPortableDatabaseDefinition($database) + protected function _getPortableDatabaseDefinition(array $database) : string { return $database['datname']; } @@ -256,7 +254,7 @@ protected function _getPortableDatabaseDefinition($database) /** * {@inheritdoc} */ - protected function _getPortableSequencesList($sequences) + protected function _getPortableSequencesList(array $sequences) : array { $sequenceDefinitions = []; @@ -282,7 +280,7 @@ protected function _getPortableSequencesList($sequences) /** * {@inheritdoc} */ - protected function getPortableNamespaceDefinition(array $namespace) + protected function getPortableNamespaceDefinition(array $namespace) : string { return $namespace['nspname']; } @@ -290,7 +288,7 @@ protected function getPortableNamespaceDefinition(array $namespace) /** * {@inheritdoc} */ - protected function _getPortableSequenceDefinition($sequence) + protected function _getPortableSequenceDefinition(array $sequence) : Sequence { if ($sequence['schemaname'] !== 'public') { $sequenceName = $sequence['schemaname'] . '.' . $sequence['relname']; @@ -311,7 +309,7 @@ protected function _getPortableSequenceDefinition($sequence) /** * {@inheritdoc} */ - protected function _getPortableTableColumnDefinition($tableColumn) + protected function _getPortableTableColumnDefinition(array $tableColumn) : Column { $tableColumn = array_change_key_case($tableColumn, CASE_LOWER); diff --git a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php index df879a87ec4..bfb34b44a21 100644 --- a/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php @@ -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 @@ public function createDatabase($database) * * @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 @@ public function stopDatabase($database) /** * {@inheritdoc} */ - protected function _getPortableDatabaseDefinition($database) + protected function _getPortableDatabaseDefinition(array $database) : string { return $database['name']; } @@ -78,7 +68,7 @@ protected function _getPortableDatabaseDefinition($database) /** * {@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 @@ protected function _getPortableSequenceDefinition($sequence) /** * {@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 @@ protected function _getPortableTableColumnDefinition($tableColumn) /** * {@inheritdoc} */ - protected function _getPortableTableDefinition($table) + protected function _getPortableTableDefinition(array $table) : string { return $table['table_name']; } @@ -149,7 +139,7 @@ protected function _getPortableTableDefinition($table) /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeyDefinition($tableForeignKey) + protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint { return new ForeignKeyConstraint( $tableForeignKey['local_columns'], @@ -163,7 +153,7 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeysList($tableForeignKeys) + protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array { $foreignKeys = []; @@ -223,7 +213,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t /** * {@inheritdoc} */ - protected function _getPortableViewDefinition($view) + protected function _getPortableViewDefinition(array $view) : View { $definition = preg_replace('/^.*\s+as\s+SELECT(.*)/i', 'SELECT$1', $view['view_def']); assert(is_string($definition)); diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index 2d80bf7388b..80d7eae06b6 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -27,7 +27,7 @@ class SQLServerSchemaManager extends AbstractSchemaManager /** * {@inheritdoc} */ - public function dropDatabase($database) + public function dropDatabase(string $database) : void { try { parent::dropDatabase($database); @@ -56,7 +56,7 @@ public function dropDatabase($database) /** * {@inheritdoc} */ - protected function _getPortableSequenceDefinition($sequence) + protected function _getPortableSequenceDefinition(array $sequence) : Sequence { return new Sequence($sequence['name'], (int) $sequence['increment'], (int) $sequence['start_value']); } @@ -64,7 +64,7 @@ protected function _getPortableSequenceDefinition($sequence) /** * {@inheritdoc} */ - protected function _getPortableTableColumnDefinition($tableColumn) + protected function _getPortableTableColumnDefinition(array $tableColumn) : Column { $dbType = strtok($tableColumn['type'], '(), '); assert(is_string($dbType)); @@ -158,7 +158,7 @@ private function parseDefaultExpression(string $value) : ?string /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeysList($tableForeignKeys) + protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array { $foreignKeys = []; @@ -200,7 +200,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeyDefinition($tableForeignKey) + protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) : ForeignKeyConstraint { return new ForeignKeyConstraint( $tableForeignKey['local_columns'], @@ -214,7 +214,7 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) /** * {@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']; @@ -226,7 +226,7 @@ protected function _getPortableTableDefinition($table) /** * {@inheritdoc} */ - protected function _getPortableDatabaseDefinition($database) + protected function _getPortableDatabaseDefinition(array $database) : string { return $database['name']; } @@ -234,7 +234,7 @@ protected function _getPortableDatabaseDefinition($database) /** * {@inheritdoc} */ - protected function getPortableNamespaceDefinition(array $namespace) + protected function getPortableNamespaceDefinition(array $namespace) : string { return $namespace['name']; } @@ -242,7 +242,7 @@ protected function getPortableNamespaceDefinition(array $namespace) /** * {@inheritdoc} */ - protected function _getPortableViewDefinition($view) + protected function _getPortableViewDefinition(array $view) : View { // @todo return new View($view['name'], ''); @@ -251,7 +251,7 @@ protected function _getPortableViewDefinition($view) /** * {@inheritdoc} */ - public function listTableIndexes($table) + public function listTableIndexes(string $table) : array { $sql = $this->_platform->getListTableIndexesSQL($table, $this->_conn->getDatabase()); @@ -277,7 +277,7 @@ public function listTableIndexes($table) /** * {@inheritdoc} */ - public function alterTable(TableDiff $tableDiff) + public function alterTable(TableDiff $tableDiff) : void { if (count($tableDiff->removedColumns) > 0) { foreach ($tableDiff->removedColumns as $col) { @@ -299,13 +299,8 @@ public function alterTable(TableDiff $tableDiff) /** * 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 @@ -320,12 +315,8 @@ private function getColumnConstraintSQL($table, $column) * 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); diff --git a/lib/Doctrine/DBAL/Schema/Schema.php b/lib/Doctrine/DBAL/Schema/Schema.php index b2fb2371abb..155578efb3c 100644 --- a/lib/Doctrine/DBAL/Schema/Schema.php +++ b/lib/Doctrine/DBAL/Schema/Schema.php @@ -47,23 +47,23 @@ class Schema extends AbstractAsset /** * The namespaces in this schema. * - * @var string[] + * @var array */ private $namespaces = []; - /** @var Table[] */ + /** @var array */ protected $_tables = []; - /** @var Sequence[] */ + /** @var array */ protected $_sequences = []; /** @var SchemaConfig */ - protected $_schemaConfig = false; + protected $_schemaConfig; /** - * @param Table[] $tables - * @param Sequence[] $sequences - * @param string[] $namespaces + * @param array $tables + * @param array $sequences + * @param array $namespaces */ public function __construct( array $tables = [], @@ -90,20 +90,15 @@ public function __construct( } } - /** - * @return bool - */ - public function hasExplicitForeignKeyIndexes() + public function hasExplicitForeignKeyIndexes() : bool { return $this->_schemaConfig->hasExplicitForeignKeyIndexes(); } /** - * @return void - * * @throws SchemaException */ - protected function _addTable(Table $table) + protected function _addTable(Table $table) : void { $namespaceName = $table->getNamespaceName(); $tableName = $table->getFullQualifiedName($this->getName()); @@ -123,11 +118,9 @@ protected function _addTable(Table $table) } /** - * @return void - * * @throws SchemaException */ - protected function _addSequence(Sequence $sequence) + protected function _addSequence(Sequence $sequence) : void { $namespaceName = $sequence->getNamespaceName(); $seqName = $sequence->getFullQualifiedName($this->getName()); @@ -148,9 +141,9 @@ protected function _addSequence(Sequence $sequence) /** * Returns the namespaces of this schema. * - * @return string[] A list of namespace names. + * @return array A list of namespace names. */ - public function getNamespaces() + public function getNamespaces() : array { return $this->namespaces; } @@ -158,21 +151,17 @@ public function getNamespaces() /** * Gets all tables of this schema. * - * @return Table[] + * @return array */ - public function getTables() + public function getTables() : array { return $this->_tables; } /** - * @param string $tableName - * - * @return Table - * * @throws SchemaException */ - public function getTable($tableName) + public function getTable(string $tableName) : Table { $tableName = $this->getFullQualifiedAssetName($tableName); if (! isset($this->_tables[$tableName])) { @@ -182,12 +171,7 @@ public function getTable($tableName) return $this->_tables[$tableName]; } - /** - * @param string $name - * - * @return string - */ - private function getFullQualifiedAssetName($name) + private function getFullQualifiedAssetName(string $name) : string { $name = $this->getUnquotedAssetName($name); @@ -200,12 +184,8 @@ private function getFullQualifiedAssetName($name) /** * Returns the unquoted representation of a given asset name. - * - * @param string $assetName Quoted or unquoted representation of an asset name. - * - * @return string */ - private function getUnquotedAssetName($assetName) + private function getUnquotedAssetName(string $assetName) : string { if ($this->isIdentifierQuoted($assetName)) { return $this->trimQuotes($assetName); @@ -216,12 +196,8 @@ private function getUnquotedAssetName($assetName) /** * Does this schema have a namespace with the given name? - * - * @param string $namespaceName - * - * @return bool */ - public function hasNamespace($namespaceName) + public function hasNamespace(string $namespaceName) : bool { $namespaceName = strtolower($this->getUnquotedAssetName($namespaceName)); @@ -230,12 +206,8 @@ public function hasNamespace($namespaceName) /** * Does this schema have a table with the given name? - * - * @param string $tableName - * - * @return bool */ - public function hasTable($tableName) + public function hasTable(string $tableName) : bool { $tableName = $this->getFullQualifiedAssetName($tableName); @@ -245,19 +217,14 @@ public function hasTable($tableName) /** * Gets all table names, prefixed with a schema name, even the default one if present. * - * @return string[] + * @return array */ - public function getTableNames() + public function getTableNames() : array { return array_keys($this->_tables); } - /** - * @param string $sequenceName - * - * @return bool - */ - public function hasSequence($sequenceName) + public function hasSequence(string $sequenceName) : bool { $sequenceName = $this->getFullQualifiedAssetName($sequenceName); @@ -265,13 +232,9 @@ public function hasSequence($sequenceName) } /** - * @param string $sequenceName - * - * @return Sequence - * * @throws SchemaException */ - public function getSequence($sequenceName) + public function getSequence(string $sequenceName) : Sequence { $sequenceName = $this->getFullQualifiedAssetName($sequenceName); if (! $this->hasSequence($sequenceName)) { @@ -282,9 +245,9 @@ public function getSequence($sequenceName) } /** - * @return Sequence[] + * @return array */ - public function getSequences() + public function getSequences() : array { return $this->_sequences; } @@ -292,13 +255,11 @@ public function getSequences() /** * Creates a new namespace. * - * @param string $namespaceName The name of the namespace to create. - * - * @return \Doctrine\DBAL\Schema\Schema This schema instance. + * @return $this * * @throws SchemaException */ - public function createNamespace($namespaceName) + public function createNamespace(string $namespaceName) : self { $unquotedNamespaceName = strtolower($this->getUnquotedAssetName($namespaceName)); @@ -313,12 +274,8 @@ public function createNamespace($namespaceName) /** * Creates a new table. - * - * @param string $tableName - * - * @return Table */ - public function createTable($tableName) + public function createTable(string $tableName) : Table { $table = new Table($tableName); $this->_addTable($table); @@ -333,12 +290,9 @@ public function createTable($tableName) /** * Renames a table. * - * @param string $oldTableName - * @param string $newTableName - * - * @return \Doctrine\DBAL\Schema\Schema + * @return $this */ - public function renameTable($oldTableName, $newTableName) + public function renameTable(string $oldTableName, string $newTableName) : self { $table = $this->getTable($oldTableName); $table->_setName($newTableName); @@ -352,11 +306,9 @@ public function renameTable($oldTableName, $newTableName) /** * Drops a table from the schema. * - * @param string $tableName - * - * @return \Doctrine\DBAL\Schema\Schema + * @return $this */ - public function dropTable($tableName) + public function dropTable(string $tableName) : self { $tableName = $this->getFullQualifiedAssetName($tableName); $this->getTable($tableName); @@ -367,14 +319,8 @@ public function dropTable($tableName) /** * Creates a new sequence. - * - * @param string $sequenceName - * @param int $allocationSize - * @param int $initialValue - * - * @return Sequence */ - public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1) + public function createSequence(string $sequenceName, int $allocationSize = 1, int $initialValue = 1) : Sequence { $seq = new Sequence($sequenceName, $allocationSize, $initialValue); $this->_addSequence($seq); @@ -383,11 +329,9 @@ public function createSequence($sequenceName, $allocationSize = 1, $initialValue } /** - * @param string $sequenceName - * - * @return \Doctrine\DBAL\Schema\Schema + * @return $this */ - public function dropSequence($sequenceName) + public function dropSequence(string $sequenceName) : self { $sequenceName = $this->getFullQualifiedAssetName($sequenceName); unset($this->_sequences[$sequenceName]); @@ -398,9 +342,9 @@ public function dropSequence($sequenceName) /** * Returns an array of necessary SQL queries to create the schema on the given platform. * - * @return string[] + * @return array */ - public function toSql(AbstractPlatform $platform) + public function toSql(AbstractPlatform $platform) : array { $sqlCollector = new CreateSchemaSqlCollector($platform); $this->visit($sqlCollector); @@ -411,9 +355,9 @@ public function toSql(AbstractPlatform $platform) /** * Return an array of necessary SQL queries to drop the schema on the given platform. * - * @return string[] + * @return array */ - public function toDropSql(AbstractPlatform $platform) + public function toDropSql(AbstractPlatform $platform) : array { $dropSqlCollector = new DropSchemaSqlCollector($platform); $this->visit($dropSqlCollector); @@ -422,9 +366,9 @@ public function toDropSql(AbstractPlatform $platform) } /** - * @return string[] + * @return array */ - public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) + public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) : array { $comparator = new Comparator(); $schemaDiff = $comparator->compare($this, $toSchema); @@ -433,9 +377,9 @@ public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) } /** - * @return string[] + * @return array */ - public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) + public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) : array { $comparator = new Comparator(); $schemaDiff = $comparator->compare($fromSchema, $this); @@ -443,10 +387,7 @@ public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform return $schemaDiff->toSql($platform); } - /** - * @return void - */ - public function visit(Visitor $visitor) + public function visit(Visitor $visitor) : void { $visitor->acceptSchema($this); diff --git a/lib/Doctrine/DBAL/Schema/SchemaConfig.php b/lib/Doctrine/DBAL/Schema/SchemaConfig.php index e3a2f36b0b4..ef2dc0b91a5 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaConfig.php +++ b/lib/Doctrine/DBAL/Schema/SchemaConfig.php @@ -15,66 +15,44 @@ class SchemaConfig /** @var int */ protected $maxIdentifierLength = 63; - /** @var string */ + /** @var string|null */ protected $name; - /** @var mixed[] */ + /** @var array */ 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 @@ public function setName($name) * Gets the default options that are passed to Table instances created with * Schema#createTable(). * - * @return mixed[] + * @return array */ - public function getDefaultTableOptions() + public function getDefaultTableOptions() : array { return $this->defaultTableOptions; } /** - * @param mixed[] $defaultTableOptions - * - * @return void + * @param array $defaultTableOptions */ - public function setDefaultTableOptions(array $defaultTableOptions) + public function setDefaultTableOptions(array $defaultTableOptions) : void { $this->defaultTableOptions = $defaultTableOptions; } diff --git a/lib/Doctrine/DBAL/Schema/SchemaDiff.php b/lib/Doctrine/DBAL/Schema/SchemaDiff.php index 97033eeeebb..6a572f3ba8e 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaDiff.php +++ b/lib/Doctrine/DBAL/Schema/SchemaDiff.php @@ -18,58 +18,58 @@ class SchemaDiff /** * All added namespaces. * - * @var string[] + * @var array */ public $newNamespaces = []; /** * All removed namespaces. * - * @var string[] + * @var array */ public $removedNamespaces = []; /** * All added tables. * - * @var Table[] + * @var array */ public $newTables = []; /** * All changed tables. * - * @var TableDiff[] + * @var array */ public $changedTables = []; /** * All removed tables. * - * @var Table[] + * @var array */ public $removedTables = []; - /** @var Sequence[] */ + /** @var array */ public $newSequences = []; - /** @var Sequence[] */ + /** @var array */ public $changedSequences = []; - /** @var Sequence[] */ + /** @var array */ public $removedSequences = []; - /** @var ForeignKeyConstraint[] */ + /** @var array */ public $orphanedForeignKeys = []; /** * Constructs an SchemaDiff object. * - * @param Table[] $newTables - * @param TableDiff[] $changedTables - * @param Table[] $removedTables + * @param array $newTables + * @param array $changedTables + * @param array $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 @@ public function __construct($newTables = [], $changedTables = [], $removedTables * * This way it is ensured that assets are deleted which might not be relevant to the metadata schema at all. * - * @return string[] + * @return array */ - public function toSaveSql(AbstractPlatform $platform) + public function toSaveSql(AbstractPlatform $platform) : array { return $this->_toSql($platform, true); } /** - * @return string[] + * @return array */ - public function toSql(AbstractPlatform $platform) + public function toSql(AbstractPlatform $platform) : array { return $this->_toSql($platform, false); } /** - * @param bool $saveMode - * - * @return string[] + * @return array */ - protected function _toSql(AbstractPlatform $platform, $saveMode = false) + protected function _toSql(AbstractPlatform $platform, bool $saveMode = false) : array { $sql = []; diff --git a/lib/Doctrine/DBAL/Schema/Sequence.php b/lib/Doctrine/DBAL/Schema/Sequence.php index 89147984136..86989250d2d 100644 --- a/lib/Doctrine/DBAL/Schema/Sequence.php +++ b/lib/Doctrine/DBAL/Schema/Sequence.php @@ -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 @@ public function __construct($name, $allocationSize = 1, $initialValue = 1, $cach $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 @@ public function setCache($cache) * * 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 @@ public function isAutoIncrementsFor(Table $table) return $tableSequenceName === $sequenceName; } - /** - * @return void - */ - public function visit(Visitor $visitor) + public function visit(Visitor $visitor) : void { $visitor->acceptSequence($this); } diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 045899af7a0..fb2e1673565 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -4,7 +4,6 @@ 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_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 @@ public function dropDatabase($database) /** * {@inheritdoc} */ - public function createDatabase($database) + public function createDatabase(string $database) : void { $params = $this->_conn->getParams(); $driver = $params['driver']; @@ -65,7 +65,7 @@ public function createDatabase($database) /** * {@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 @@ public function renameTable($name, $newName) /** * {@inheritdoc} */ - public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) + public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) : void { - $tableDiff = $this->getTableDiffForAlterForeignKey($table); + $table = $this->ensureTable($table); + + $tableDiff = $this->getTableDiffForAlterForeignKey($table); + $tableDiff->addedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -87,9 +90,12 @@ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) /** * {@inheritdoc} */ - public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) + public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) : void { - $tableDiff = $this->getTableDiffForAlterForeignKey($table); + $table = $this->ensureTable($table); + + $tableDiff = $this->getTableDiffForAlterForeignKey($table); + $tableDiff->changedForeignKeys[] = $foreignKey; $this->alterTable($tableDiff); @@ -98,10 +104,17 @@ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table /** * {@inheritdoc} */ - public function dropForeignKey($foreignKey, $table) + public function dropForeignKey($foreignKey, $table) : void { - $tableDiff = $this->getTableDiffForAlterForeignKey($table); - $tableDiff->removedForeignKeys[] = $foreignKey; + $table = $this->ensureTable($table); + + $tableDiff = $this->getTableDiffForAlterForeignKey($table); + + if (is_string($foreignKey)) { + $tableDiff->removedForeignKeys[] = $table->getForeignKey($foreignKey); + } else { + $tableDiff->removedForeignKeys[] = $foreignKey; + } $this->alterTable($tableDiff); } @@ -109,7 +122,7 @@ public function dropForeignKey($foreignKey, $table) /** * {@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 @@ public function listTableForeignKeys($table, $database = null) /** * {@inheritdoc} */ - protected function _getPortableTableDefinition($table) + protected function _getPortableTableDefinition(array $table) : string { return $table['name']; } @@ -226,18 +239,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t /** * {@inheritdoc} */ - 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); @@ -295,7 +297,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) /** * {@inheritdoc} */ - protected function _getPortableTableColumnDefinition($tableColumn) + protected function _getPortableTableColumnDefinition(array $tableColumn) : Column { preg_match('/^([^()]*)\\s*(\\(((\\d+)(,\\s*(\\d+))?)\\))?/', $tableColumn['type'], $matches); @@ -357,7 +359,7 @@ protected function _getPortableTableColumnDefinition($tableColumn) /** * {@inheritdoc} */ - protected function _getPortableViewDefinition($view) + protected function _getPortableViewDefinition(array $view) : View { return new View($view['name'], $view['sql']); } @@ -365,7 +367,7 @@ protected function _getPortableViewDefinition($view) /** * {@inheritdoc} */ - protected function _getPortableTableForeignKeysList($tableForeignKeys) + protected function _getPortableTableForeignKeysList(array $tableForeignKeys) : array { $list = []; foreach ($tableForeignKeys as $value) { @@ -413,31 +415,26 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) return $result; } - /** - * @param Table|string $table - * - * @return TableDiff - * - * @throws DBALException - */ - private function getTableDiffForAlterForeignKey($table) + private function getTableDiffForAlterForeignKey(Table $table) : TableDiff { - if (! $table instanceof Table) { - $tableDetails = $this->tryMethod('listTableDetails', $table); - - if ($tableDetails === false) { - throw new DBALException(sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table)); - } - - $table = $tableDetails; - } - $tableDiff = new TableDiff($table->getName()); $tableDiff->fromTable = $table; return $tableDiff; } + /** + * @param string|Table $table + */ + private function ensureTable($table) : Table + { + if (is_string($table)) { + $table = $this->listTableDetails($table); + } + + return $table; + } + private function parseColumnCollationFromSQL(string $column, string $sql) : ?string { $pattern = '{(?:\W' . preg_quote($column) . '\W|\W' . preg_quote($this->_platform->quoteSingleIdentifier($column)) diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php index 74dce854098..3ec2ebd649f 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/AbstractSchemaSynchronizer.php @@ -21,9 +21,9 @@ public function __construct(Connection $conn) } /** - * @param string[] $sql + * @param array $sql */ - protected function processSqlSafely(array $sql) + protected function processSqlSafely(array $sql) : void { foreach ($sql as $s) { try { @@ -34,9 +34,9 @@ protected function processSqlSafely(array $sql) } /** - * @param string[] $sql + * @param array $sql */ - protected function processSql(array $sql) + protected function processSql(array $sql) : void { foreach ($sql as $s) { $this->conn->exec($s); diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php index 8e0eb117c4f..58ab02e67d5 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SchemaSynchronizer.php @@ -15,60 +15,48 @@ interface SchemaSynchronizer /** * Gets the SQL statements that can be executed to create the schema. * - * @return string[] + * @return array */ - 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 */ - 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 */ - 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; } diff --git a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php index 83abc250596..605add99cc6 100644 --- a/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php +++ b/lib/Doctrine/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizer.php @@ -28,7 +28,7 @@ public function __construct(Connection $conn) /** * {@inheritdoc} */ - public function getCreateSchema(Schema $createSchema) + public function getCreateSchema(Schema $createSchema) : array { return $createSchema->toSql($this->platform); } @@ -36,7 +36,7 @@ public function getCreateSchema(Schema $createSchema) /** * {@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 @@ public function getUpdateSchema(Schema $toSchema, $noDrops = false) /** * {@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 @@ public function getDropSchema(Schema $dropSchema) /** * {@inheritdoc} */ - public function getDropAllSchema() + public function getDropAllSchema() : array { $sm = $this->conn->getSchemaManager(); $visitor = new DropSchemaSqlCollector($this->platform); @@ -128,7 +128,7 @@ public function getDropAllSchema() /** * {@inheritdoc} */ - public function createSchema(Schema $createSchema) + public function createSchema(Schema $createSchema) : void { $this->processSql($this->getCreateSchema($createSchema)); } @@ -136,7 +136,7 @@ public function createSchema(Schema $createSchema) /** * {@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 @@ public function updateSchema(Schema $toSchema, $noDrops = false) /** * {@inheritdoc} */ - public function dropSchema(Schema $dropSchema) + public function dropSchema(Schema $dropSchema) : void { $this->processSqlSafely($this->getDropSchema($dropSchema)); } @@ -152,7 +152,7 @@ public function dropSchema(Schema $dropSchema) /** * {@inheritdoc} */ - public function dropAllSchema() + public function dropAllSchema() : void { $this->processSql($this->getDropAllSchema()); } diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 8dfef9ac6e7..3a58e26668a 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -57,17 +57,16 @@ class Table extends AbstractAsset protected $_schemaConfig = null; /** - * @param string $tableName - * @param Column[] $columns - * @param Index[] $indexes - * @param UniqueConstraint[] $uniqueConstraints - * @param ForeignKeyConstraint[] $fkConstraints - * @param mixed[] $options + * @param array $columns + * @param array $indexes + * @param array $uniqueConstraints + * @param array $fkConstraints + * @param array $options * * @throws DBALException */ public function __construct( - $tableName, + string $tableName, array $columns = [], array $indexes = [], array $uniqueConstraints = [], @@ -99,10 +98,7 @@ public function __construct( $this->_options = $options; } - /** - * @return void - */ - public function setSchemaConfig(SchemaConfig $schemaConfig) + public function setSchemaConfig(SchemaConfig $schemaConfig) : void { $this->_schemaConfig = $schemaConfig; } @@ -110,12 +106,9 @@ public function setSchemaConfig(SchemaConfig $schemaConfig) /** * Sets the Primary Key. * - * @param string[] $columnNames - * @param string|false $indexName - * - * @return self + * @param array $columnNames */ - public function setPrimaryKey(array $columnNames, $indexName = false) + public function setPrimaryKey(array $columnNames, ?string $indexName = null) : self { $this->_addIndex($this->_createIndex($columnNames, $indexName ?: 'primary', true, true)); @@ -128,14 +121,11 @@ public function setPrimaryKey(array $columnNames, $indexName = false) } /** - * @param mixed[] $columnNames - * @param string|null $indexName - * @param string[] $flags - * @param mixed[] $options - * - * @return self + * @param array $columnNames + * @param array $flags + * @param array $options */ - public function addUniqueConstraint(array $columnNames, $indexName = null, array $flags = [], array $options = []) + public function addUniqueConstraint(array $columnNames, ?string $indexName = null, array $flags = [], array $options = []) : self { if ($indexName === null) { $indexName = $this->_generateIdentifierName( @@ -149,14 +139,11 @@ public function addUniqueConstraint(array $columnNames, $indexName = null, array } /** - * @param string[] $columnNames - * @param string|null $indexName - * @param string[] $flags - * @param mixed[] $options - * - * @return self + * @param array $columnNames + * @param array $flags + * @param array $options */ - public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = []) + public function addIndex(array $columnNames, ?string $indexName = null, array $flags = [], array $options = []) : self { if ($indexName === null) { $indexName = $this->_generateIdentifierName( @@ -171,10 +158,8 @@ public function addIndex(array $columnNames, $indexName = null, array $flags = [ /** * Drops the primary key from this table. - * - * @return void */ - public function dropPrimaryKey() + public function dropPrimaryKey() : void { $this->dropIndex($this->_primaryKeyName); $this->_primaryKeyName = false; @@ -183,13 +168,9 @@ public function dropPrimaryKey() /** * Drops an index from this table. * - * @param string $indexName The index name. - * - * @return void - * * @throws SchemaException If the index does not exist. */ - public function dropIndex($indexName) + public function dropIndex(string $indexName) : void { $indexName = $this->normalizeIdentifier($indexName); @@ -201,13 +182,10 @@ public function dropIndex($indexName) } /** - * @param string[] $columnNames - * @param string|null $indexName - * @param mixed[] $options - * - * @return self + * @param array $columnNames + * @param array $options */ - public function addUniqueIndex(array $columnNames, $indexName = null, array $options = []) + public function addUniqueIndex(array $columnNames, ?string $indexName = null, array $options = []) : self { if ($indexName === null) { $indexName = $this->_generateIdentifierName( @@ -227,12 +205,10 @@ public function addUniqueIndex(array $columnNames, $indexName = null, array $opt * @param string|null $newIndexName The name of the index to rename to. * If null is given, the index name will be auto-generated. * - * @return self This table instance. - * * @throws SchemaException If no index exists for the given current name * or if an index with the given new name already exists on this table. */ - public function renameIndex($oldIndexName, $newIndexName = null) + public function renameIndex(string $oldIndexName, ?string $newIndexName = null) : self { $oldIndexName = $this->normalizeIdentifier($oldIndexName); $normalizedNewIndexName = $this->normalizeIdentifier($newIndexName); @@ -254,7 +230,7 @@ public function renameIndex($oldIndexName, $newIndexName = null) if ($oldIndex->isPrimary()) { $this->dropPrimaryKey(); - return $this->setPrimaryKey($oldIndex->getColumns(), $newIndexName ?? false); + return $this->setPrimaryKey($oldIndex->getColumns(), $newIndexName ?? null); } unset($this->_indexes[$oldIndexName]); @@ -269,11 +245,9 @@ public function renameIndex($oldIndexName, $newIndexName = null) /** * Checks if an index begins in the order of the given columns. * - * @param string[] $columnNames - * - * @return bool + * @param array $columnNames */ - public function columnsAreIndexed(array $columnNames) + public function columnsAreIndexed(array $columnNames) : bool { foreach ($this->getIndexes() as $index) { /** @var $index Index */ @@ -286,13 +260,9 @@ public function columnsAreIndexed(array $columnNames) } /** - * @param string $columnName - * @param string $typeName - * @param mixed[] $options - * - * @return Column + * @param array $options */ - public function addColumn($columnName, $typeName, array $options = []) + public function addColumn(string $columnName, string $typeName, array $options = []) : Column { $column = new Column($columnName, Type::getType($typeName), $options); @@ -304,12 +274,9 @@ public function addColumn($columnName, $typeName, array $options = []) /** * Change Column Details. * - * @param string $columnName - * @param mixed[] $options - * - * @return self + * @param array $options */ - public function changeColumn($columnName, array $options) + public function changeColumn(string $columnName, array $options) : self { $column = $this->getColumn($columnName); @@ -320,12 +287,8 @@ public function changeColumn($columnName, array $options) /** * Drops a Column from the Table. - * - * @param string $columnName - * - * @return self */ - public function dropColumn($columnName) + public function dropColumn(string $columnName) : self { $columnName = $this->normalizeIdentifier($columnName); @@ -339,15 +302,12 @@ public function dropColumn($columnName) * * Name is inferred from the local columns. * - * @param Table|string $foreignTable Table schema instance or table name - * @param string[] $localColumnNames - * @param string[] $foreignColumnNames - * @param mixed[] $options - * @param string|null $name - * - * @return self + * @param Table|string $foreignTable Table schema instance or table name + * @param array $localColumnNames + * @param array $foreignColumnNames + * @param array $options */ - public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null) + public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], ?string $name = null) : self { if (! $name) { $name = $this->_generateIdentifierName( @@ -383,12 +343,9 @@ public function addForeignKeyConstraint($foreignTable, array $localColumnNames, } /** - * @param string $name - * @param mixed $value - * - * @return self + * @param mixed $value */ - public function addOption($name, $value) + public function addOption(string $name, $value) : self { $this->_options[$name] = $value; @@ -397,12 +354,8 @@ public function addOption($name, $value) /** * Returns whether this table has a foreign key constraint with the given name. - * - * @param string $constraintName - * - * @return bool */ - public function hasForeignKey($constraintName) + public function hasForeignKey(string $constraintName) : bool { $constraintName = $this->normalizeIdentifier($constraintName); @@ -412,13 +365,9 @@ public function hasForeignKey($constraintName) /** * Returns the foreign key constraint with the given name. * - * @param string $constraintName The constraint name. - * - * @return ForeignKeyConstraint - * * @throws SchemaException If the foreign key does not exist. */ - public function getForeignKey($constraintName) + public function getForeignKey(string $constraintName) : ForeignKeyConstraint { $constraintName = $this->normalizeIdentifier($constraintName); @@ -432,13 +381,9 @@ public function getForeignKey($constraintName) /** * Removes the foreign key constraint with the given name. * - * @param string $constraintName The constraint name. - * - * @return void - * * @throws SchemaException */ - public function removeForeignKey($constraintName) + public function removeForeignKey(string $constraintName) : void { $constraintName = $this->normalizeIdentifier($constraintName); @@ -451,12 +396,8 @@ public function removeForeignKey($constraintName) /** * Returns whether this table has a unique constraint with the given name. - * - * @param string $constraintName - * - * @return bool */ - public function hasUniqueConstraint($constraintName) + public function hasUniqueConstraint(string $constraintName) : bool { $constraintName = $this->normalizeIdentifier($constraintName); @@ -466,13 +407,9 @@ public function hasUniqueConstraint($constraintName) /** * Returns the unique constraint with the given name. * - * @param string $constraintName The constraint name. - * - * @return UniqueConstraint - * * @throws SchemaException If the foreign key does not exist. */ - public function getUniqueConstraint($constraintName) + public function getUniqueConstraint(string $constraintName) : UniqueConstraint { $constraintName = $this->normalizeIdentifier($constraintName); @@ -486,13 +423,9 @@ public function getUniqueConstraint($constraintName) /** * Removes the unique constraint with the given name. * - * @param string $constraintName The constraint name. - * - * @return void - * * @throws SchemaException */ - public function removeUniqueConstraint($constraintName) + public function removeUniqueConstraint(string $constraintName) : void { $constraintName = $this->normalizeIdentifier($constraintName); @@ -506,9 +439,9 @@ public function removeUniqueConstraint($constraintName) /** * Returns ordered list of columns (primary keys are first, then foreign keys, then the rest) * - * @return Column[] + * @return array */ - public function getColumns() + public function getColumns() : array { $columns = $this->_columns; $pkCols = []; @@ -536,12 +469,8 @@ public function getColumns() /** * Returns whether this table has a Column with the given name. - * - * @param string $columnName The column name. - * - * @return bool */ - public function hasColumn($columnName) + public function hasColumn(string $columnName) : bool { $columnName = $this->normalizeIdentifier($columnName); @@ -551,13 +480,9 @@ public function hasColumn($columnName) /** * Returns the Column with the given name. * - * @param string $columnName The column name. - * - * @return Column - * * @throws SchemaException If the column does not exist. */ - public function getColumn($columnName) + public function getColumn(string $columnName) : Column { $columnName = $this->normalizeIdentifier($columnName); @@ -570,10 +495,8 @@ public function getColumn($columnName) /** * Returns the primary key. - * - * @return Index|null The primary key, or null if this Table has no primary key. */ - public function getPrimaryKey() + public function getPrimaryKey() : ?Index { return $this->hasPrimaryKey() ? $this->getIndex($this->_primaryKeyName) @@ -583,11 +506,11 @@ public function getPrimaryKey() /** * Returns the primary key columns. * - * @return string[] + * @return array * * @throws DBALException */ - public function getPrimaryKeyColumns() + public function getPrimaryKeyColumns() : array { $primaryKey = $this->getPrimaryKey(); @@ -600,22 +523,16 @@ public function getPrimaryKeyColumns() /** * Returns whether this table has a primary key. - * - * @return bool */ - public function hasPrimaryKey() + public function hasPrimaryKey() : bool { return $this->_primaryKeyName && $this->hasIndex($this->_primaryKeyName); } /** * Returns whether this table has an Index with the given name. - * - * @param string $indexName The index name. - * - * @return bool */ - public function hasIndex($indexName) + public function hasIndex(string $indexName) : bool { $indexName = $this->normalizeIdentifier($indexName); @@ -625,13 +542,9 @@ public function hasIndex($indexName) /** * Returns the Index with the given name. * - * @param string $indexName The index name. - * - * @return Index - * * @throws SchemaException If the index does not exist. */ - public function getIndex($indexName) + public function getIndex(string $indexName) : Index { $indexName = $this->normalizeIdentifier($indexName); @@ -643,9 +556,9 @@ public function getIndex($indexName) } /** - * @return Index[] + * @return array */ - public function getIndexes() + public function getIndexes() : array { return $this->_indexes; } @@ -653,9 +566,9 @@ public function getIndexes() /** * Returns the unique constraints. * - * @return UniqueConstraint[] + * @return array */ - public function getUniqueConstraints() + public function getUniqueConstraints() : array { return $this->_uniqueConstraints; } @@ -663,45 +576,35 @@ public function getUniqueConstraints() /** * Returns the foreign key constraints. * - * @return ForeignKeyConstraint[] + * @return array */ public function getForeignKeys() { return $this->_fkConstraints; } - /** - * @param string $name - * - * @return bool - */ - public function hasOption($name) + public function hasOption(string $name) : bool { return isset($this->_options[$name]); } /** - * @param string $name - * * @return mixed */ - public function getOption($name) + public function getOption(string $name) { return $this->_options[$name]; } /** - * @return mixed[] + * @return array */ - public function getOptions() + public function getOptions() : array { return $this->_options; } - /** - * @return void - */ - public function visit(Visitor $visitor) + public function visit(Visitor $visitor) : void { $visitor->acceptTable($this); @@ -739,10 +642,7 @@ public function __clone() } } - /** - * @return int - */ - protected function _getMaxIdentifierLength() + protected function _getMaxIdentifierLength() : int { return $this->_schemaConfig instanceof SchemaConfig ? $this->_schemaConfig->getMaxIdentifierLength() @@ -750,11 +650,9 @@ protected function _getMaxIdentifierLength() } /** - * @return void - * * @throws SchemaException */ - protected function _addColumn(Column $column) + protected function _addColumn(Column $column) : void { $columnName = $column->getName(); $columnName = $this->normalizeIdentifier($columnName); @@ -769,11 +667,9 @@ protected function _addColumn(Column $column) /** * Adds an index to the table. * - * @return self - * * @throws SchemaException */ - protected function _addIndex(Index $indexCandidate) + protected function _addIndex(Index $indexCandidate) : self { $indexName = $indexCandidate->getName(); $indexName = $this->normalizeIdentifier($indexName); @@ -806,10 +702,7 @@ protected function _addIndex(Index $indexCandidate) return $this; } - /** - * @return self - */ - protected function _addUniqueConstraint(UniqueConstraint $constraint) + protected function _addUniqueConstraint(UniqueConstraint $constraint) : self { $name = strlen($constraint->getName()) ? $constraint->getName() @@ -845,10 +738,7 @@ protected function _addUniqueConstraint(UniqueConstraint $constraint) return $this; } - /** - * @return self - */ - protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) + protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) : self { $constraint->setLocalTable($this); @@ -892,12 +782,8 @@ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) * Normalizes a given identifier. * * Trims quotes and lowercases the given identifier. - * - * @param string|null $identifier The identifier to normalize. - * - * @return string The normalized identifier. */ - private function normalizeIdentifier($identifier) + private function normalizeIdentifier(?string $identifier) : string { if ($identifier === null) { return ''; @@ -907,16 +793,13 @@ private function normalizeIdentifier($identifier) } /** - * @param mixed[] $columns - * @param string $indexName - * @param mixed[] $flags - * @param mixed[] $options - * - * @return UniqueConstraint + * @param array $columns + * @param array $flags + * @param array $options * * @throws SchemaException */ - private function _createUniqueConstraint(array $columns, $indexName, array $flags = [], array $options = []) + private function _createUniqueConstraint(array $columns, string $indexName, array $flags = [], array $options = []) : UniqueConstraint { if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) { throw IndexNameInvalid::new($indexName); @@ -938,18 +821,13 @@ private function _createUniqueConstraint(array $columns, $indexName, array $flag } /** - * @param mixed[] $columns - * @param string $indexName - * @param bool $isUnique - * @param bool $isPrimary - * @param string[] $flags - * @param mixed[] $options - * - * @return Index + * @param array $columns + * @param array $flags + * @param array $options * * @throws SchemaException */ - private function _createIndex(array $columns, $indexName, $isUnique, $isPrimary, array $flags = [], array $options = []) + private function _createIndex(array $columns, string $indexName, bool $isUnique, bool $isPrimary, array $flags = [], array $options = []) : Index { if (preg_match('(([^a-zA-Z0-9_]+))', $this->normalizeIdentifier($indexName))) { throw IndexNameInvalid::new($indexName); diff --git a/lib/Doctrine/DBAL/Schema/TableDiff.php b/lib/Doctrine/DBAL/Schema/TableDiff.php index bdbce7da3b3..0a8cf138a09 100644 --- a/lib/Doctrine/DBAL/Schema/TableDiff.php +++ b/lib/Doctrine/DBAL/Schema/TableDiff.php @@ -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 */ public $addedColumns; /** * All changed fields. * - * @var ColumnDiff[] + * @var array */ public $changedColumns = []; /** * All removed fields. * - * @var Column[] + * @var array */ public $removedColumns = []; /** * Columns that are only renamed from key to column instance name. * - * @var Column[] + * @var array */ public $renamedColumns = []; /** * All added indexes. * - * @var Index[] + * @var array */ public $addedIndexes = []; /** * All changed indexes. * - * @var Index[] + * @var array */ public $changedIndexes = []; /** * All removed indexes * - * @var Index[] + * @var array */ public $removedIndexes = []; /** * Indexes that are only renamed but are identical otherwise. * - * @var Index[] + * @var array */ public $renamedIndexes = []; /** * All added foreign key definitions * - * @var ForeignKeyConstraint[] + * @var array */ public $addedForeignKeys = []; /** * All changed foreign keys * - * @var ForeignKeyConstraint[] + * @var array */ public $changedForeignKeys = []; /** * All removed foreign keys * - * @var ForeignKeyConstraint[]|string[] + * @var array */ 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 $addedColumns + * @param array $changedColumns + * @param array $removedColumns + * @param array $addedIndexes + * @param array $changedIndexes + * @param array $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 @@ public function __construct( /** * @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); diff --git a/lib/Doctrine/DBAL/Schema/UniqueConstraint.php b/lib/Doctrine/DBAL/Schema/UniqueConstraint.php index 2ffe6022ab5..75d6f76b391 100644 --- a/lib/Doctrine/DBAL/Schema/UniqueConstraint.php +++ b/lib/Doctrine/DBAL/Schema/UniqueConstraint.php @@ -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 */ protected $columns = []; /** * Platform specific flags - * array($flagName => true) * - * @var true[] + * @var array */ protected $flags = []; /** * Platform specific options * - * @var mixed[] + * @var array */ private $options = []; /** - * @param string $indexName - * @param string[] $columns - * @param string[] $flags - * @param mixed[] $options + * @param array $columns + * @param array $flags + * @param array $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 @@ public function __construct($indexName, array $columns, array $flags = [], array /** * {@inheritdoc} */ - public function getColumns() + public function getColumns() : array { return array_keys($this->columns); } @@ -69,7 +66,7 @@ public function getColumns() /** * {@inheritdoc} */ - public function getQuotedColumns(AbstractPlatform $platform) + public function getQuotedColumns(AbstractPlatform $platform) : array { $columns = []; @@ -81,9 +78,9 @@ public function getQuotedColumns(AbstractPlatform $platform) } /** - * @return string[] + * @return array */ - public function getUnquotedColumns() + public function getUnquotedColumns() : array { return array_map([$this, 'trimQuotes'], $this->getColumns()); } @@ -91,9 +88,9 @@ public function getUnquotedColumns() /** * Returns platform specific flags for unique constraint. * - * @return string[] + * @return array */ - public function getFlags() + public function getFlags() : array { return array_keys($this->flags); } @@ -101,13 +98,9 @@ public function getFlags() /** * 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 @@ public function addFlag($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)]); } /** * 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 */ - public function getOptions() + public function getOptions() : array { return $this->options; } diff --git a/lib/Doctrine/DBAL/Schema/View.php b/lib/Doctrine/DBAL/Schema/View.php index 18ca8664c9e..f67b203036e 100644 --- a/lib/Doctrine/DBAL/Schema/View.php +++ b/lib/Doctrine/DBAL/Schema/View.php @@ -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; } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php index 318ba1f1126..bb3abff57f9 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/AbstractVisitor.php @@ -16,34 +16,34 @@ */ 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 { } } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index cea93eeb4f1..ccba4688c95 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -12,16 +12,16 @@ class CreateSchemaSqlCollector extends AbstractVisitor { - /** @var string[] */ + /** @var array */ private $createNamespaceQueries = []; - /** @var string[] */ + /** @var array */ private $createTableQueries = []; - /** @var string[] */ + /** @var array */ private $createSequenceQueries = []; - /** @var string[] */ + /** @var array */ private $createFkConstraintQueries = []; /** @var AbstractPlatform */ @@ -35,7 +35,7 @@ public function __construct(AbstractPlatform $platform) /** * {@inheritdoc} */ - public function acceptNamespace($namespaceName) + public function acceptNamespace(string $namespaceName) : void { if (! $this->platform->supportsSchemas()) { return; @@ -47,7 +47,7 @@ public function acceptNamespace($namespaceName) /** * {@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 @@ public function acceptTable(Table $table) /** * {@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 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons /** * {@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 @@ public function resetQueries() /** * Gets all queries collected so far. * - * @return string[] + * @return array */ - public function getQueries() + public function getQueries() : array { return array_merge( $this->createNamespaceQueries, diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index 59d8e04a851..f51b547a44a 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -38,7 +38,7 @@ public function __construct(AbstractPlatform $platform) /** * {@inheritdoc} */ - public function acceptTable(Table $table) + public function acceptTable(Table $table) : void { $this->tables->attach($table); } @@ -46,7 +46,7 @@ public function acceptTable(Table $table) /** * {@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 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons /** * {@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 @@ public function clearQueries() } /** - * @return string[] + * @return array */ - public function getQueries() + public function getQueries() : array { $sql = []; diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php index 96aa180133a..3f81b5c217c 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Graphviz.php @@ -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 @@ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkCons /** * {@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 @@ public function acceptSchema(Schema $schema) /** * {@inheritdoc} */ - public function acceptTable(Table $table) + public function acceptTable(Table $table) : void { $this->output .= $this->createNode( $table->getName(), @@ -63,10 +63,7 @@ public function acceptTable(Table $table) ); } - /** - * @return string - */ - private function createTableLabel(Table $table) + private function createTableLabel(Table $table) : string { // Start the table $label = '<
'; @@ -99,12 +96,9 @@ private function createTableLabel(Table $table) } /** - * @param string $name - * @param string[] $options - * - * @return string + * @param array $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 @@ private function createNode($name, $options) } /** - * @param string $node1 - * @param string $node2 - * @param string[] $options - * - * @return string + * @param array $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 @@ private function createNodeRelation($node1, $node2, $options) /** * Get Graphviz Output - * - * @return string */ - public function getOutput() + public function getOutput() : string { return $this->output . '}'; } @@ -150,12 +138,8 @@ public function getOutput() * 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()); } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php index fd09ff7cdab..90e10b91b70 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/NamespaceVisitor.php @@ -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; } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php index 196e43e46c3..78991298872 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/RemoveNamespacedAssets.php @@ -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 @@ public function acceptSchema(Schema $schema) /** * {@inheritdoc} */ - public function acceptTable(Table $table) + public function acceptTable(Table $table) : void { if ($table->isInDefaultNamespace($this->schema->getName())) { return; @@ -48,7 +48,7 @@ public function acceptTable(Table $table) /** * {@inheritdoc} */ - public function acceptSequence(Sequence $sequence) + public function acceptSequence(Sequence $sequence) : void { if ($sequence->isInDefaultNamespace($this->schema->getName())) { return; @@ -60,7 +60,7 @@ public function acceptSequence(Sequence $sequence) /** * {@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 diff --git a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php index 3d80991c4d9..071f0ebf177 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/Visitor.php @@ -16,33 +16,15 @@ */ interface Visitor { - /** - * @return void - */ - public function acceptSchema(Schema $schema); - - /** - * @return void - */ - public function acceptTable(Table $table); - - /** - * @return void - */ - public function acceptColumn(Table $table, Column $column); - - /** - * @return void - */ - public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint); - - /** - * @return void - */ - public function acceptIndex(Table $table, Index $index); - - /** - * @return void - */ - public function acceptSequence(Sequence $sequence); + public function acceptSchema(Schema $schema) : void; + + public function acceptTable(Table $table) : void; + + public function acceptColumn(Table $table, Column $column) : void; + + public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) : void; + + public function acceptIndex(Table $table, Index $index) : void; + + public function acceptSequence(Sequence $sequence) : void; } diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php index d7501b27897..c372f416fca 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/SQLAzureFederationsSynchronizer.php @@ -44,7 +44,7 @@ public function __construct(Connection $conn, SQLAzureShardManager $shardManager /** * {@inheritdoc} */ - public function getCreateSchema(Schema $createSchema) + public function getCreateSchema(Schema $createSchema) : array { $sql = []; @@ -73,7 +73,7 @@ public function getCreateSchema(Schema $createSchema) /** * {@inheritdoc} */ - public function getUpdateSchema(Schema $toSchema, $noDrops = false) + public function getUpdateSchema(Schema $toSchema, bool $noDrops = false) : array { return $this->work($toSchema, static function ($synchronizer, $schema) use ($noDrops) { return $synchronizer->getUpdateSchema($schema, $noDrops); @@ -83,7 +83,7 @@ public function getUpdateSchema(Schema $toSchema, $noDrops = false) /** * {@inheritdoc} */ - public function getDropSchema(Schema $dropSchema) + public function getDropSchema(Schema $dropSchema) : array { return $this->work($dropSchema, static function ($synchronizer, $schema) { return $synchronizer->getDropSchema($schema); @@ -93,7 +93,7 @@ public function getDropSchema(Schema $dropSchema) /** * {@inheritdoc} */ - public function createSchema(Schema $createSchema) + public function createSchema(Schema $createSchema) : void { $this->processSql($this->getCreateSchema($createSchema)); } @@ -101,7 +101,7 @@ public function createSchema(Schema $createSchema) /** * {@inheritdoc} */ - public function updateSchema(Schema $toSchema, $noDrops = false) + public function updateSchema(Schema $toSchema, bool $noDrops = false) : void { $this->processSql($this->getUpdateSchema($toSchema, $noDrops)); } @@ -109,7 +109,7 @@ public function updateSchema(Schema $toSchema, $noDrops = false) /** * {@inheritdoc} */ - public function dropSchema(Schema $dropSchema) + public function dropSchema(Schema $dropSchema) : void { $this->processSqlSafely($this->getDropSchema($dropSchema)); } @@ -117,7 +117,7 @@ public function dropSchema(Schema $dropSchema) /** * {@inheritdoc} */ - public function getDropAllSchema() + public function getDropAllSchema() : array { $this->shardManager->selectGlobal(); $globalSql = $this->synchronizer->getDropAllSchema(); @@ -150,7 +150,7 @@ public function getDropAllSchema() /** * {@inheritdoc} */ - public function dropAllSchema() + public function dropAllSchema() : void { $this->processSqlSafely($this->getDropAllSchema()); } diff --git a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php index 21f3762ba0c..da5328aed8f 100644 --- a/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php +++ b/lib/Doctrine/DBAL/Sharding/SQLAzure/Schema/MultiTenantVisitor.php @@ -68,7 +68,7 @@ public function __construct(array $excludedTables = [], $tenantColumnName = 'ten /** * {@inheritdoc} */ - public function acceptTable(Table $table) + public function acceptTable(Table $table) : void { if (in_array($table->getName(), $this->excludedTables)) { return; @@ -117,35 +117,35 @@ private function getClusteredIndex($table) /** * {@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 { } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php index 4c51c700e6a..4d8de731dac 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOSqlite/DriverTest.php @@ -40,4 +40,9 @@ protected function createDriver() { return new Driver(); } + + protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string + { + return ''; + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php index 6a744161e44..7f00c93efd0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/NamedParametersTest.php @@ -153,7 +153,7 @@ protected function setUp() : void { parent::setUp(); - if ($this->connection->getSchemaManager()->tablesExist('ddc1372_foobar')) { + if ($this->connection->getSchemaManager()->tableExists('ddc1372_foobar')) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php index 13503e3187b..ad8fd6ed92a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/ComparatorTest.php @@ -39,7 +39,7 @@ public function testDefaultValueComparison(string $type, $value) : void $onlineTable = $this->schemaManager->listTableDetails('default_value'); - self::assertFalse($this->comparator->diffTable($table, $onlineTable)); + self::assertNull($this->comparator->diffTable($table, $onlineTable)); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php index 6847ff3af61..0a7b7571612 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/MySqlSchemaManagerTest.php @@ -5,6 +5,8 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; use DateTime; +use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Exception\DatabaseRequired; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Schema\Comparator; @@ -12,6 +14,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; +use Doctrine\Tests\TestUtil; use Doctrine\Tests\Types\MySqlPointType; class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase @@ -71,7 +74,7 @@ public function testDiffTableBug() $comparator = new Comparator(); $diff = $comparator->diffTable($tableFetched, $table); - self::assertFalse($diff, 'no changes expected.'); + self::assertNull($diff, 'no changes expected.'); } public function testFulltextIndex() @@ -360,7 +363,7 @@ public function testDiffListGuidTableColumn() $comparator = new Comparator(); - self::assertFalse( + self::assertNull( $comparator->diffTable($offlineTable, $onlineTable), 'No differences should be detected with the offline vs online schema.' ); @@ -439,7 +442,7 @@ public function testColumnDefaultCurrentTimestamp() : void $comparator = new Comparator(); $diff = $comparator->diffTable($table, $onlineTable); - self::assertFalse($diff, 'Tables should be identical with column defaults.'); + self::assertNull($diff, 'Tables should be identical with column defaults.'); } public function testColumnDefaultsAreValid() @@ -514,7 +517,7 @@ public function testColumnDefaultValuesCurrentTimeAndDate() : void $comparator = new Comparator(); $diff = $comparator->diffTable($table, $onlineTable); - self::assertFalse($diff, 'Tables should be identical with column defauts time and date.'); + self::assertNull($diff, 'Tables should be identical with column defauts time and date.'); } public function testEnsureTableOptionsAreReflectedInMetadata() : void @@ -566,4 +569,18 @@ public function testParseNullCreateOptions() : void self::assertEquals([], $table->getOption('create_options')); } + + public function testListTableColumnsThrowsDatabaseRequired() : void + { + $params = TestUtil::getConnectionParams(); + unset($params['dbname']); + + $connection = DriverManager::getConnection($params); + $schemaManager = $connection->getSchemaManager(); + + self::expectException(DatabaseRequired::class); + self::expectExceptionMessage('A database is required for the method: Doctrine\DBAL\Schema\AbstractSchemaManager::listTableColumns'); + + $schemaManager->listTableColumns('users'); + } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php index df130ca1caf..d7fd1e5333a 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/PostgreSqlSchemaManagerTest.php @@ -300,7 +300,7 @@ public function testBooleanDefault() $c = new Comparator(); $diff = $c->diffTable($table, $databaseTable); - self::assertFalse($diff); + self::assertNull($diff); } public function testListTableWithBinary() @@ -339,7 +339,7 @@ public function testListQuotedTable() $comparator = new Schema\Comparator(); - self::assertFalse($comparator->diffTable($offlineTable, $onlineTable)); + self::assertNull($comparator->diffTable($offlineTable, $onlineTable)); } public function testListTablesExcludesViews() @@ -385,7 +385,7 @@ public function testPartialIndexes() $comparator = new Schema\Comparator(); - self::assertFalse($comparator->diffTable($offlineTable, $onlineTable)); + self::assertNull($comparator->diffTable($offlineTable, $onlineTable)); self::assertTrue($onlineTable->hasIndex('simple_partial_index')); self::assertTrue($onlineTable->getIndex('simple_partial_index')->hasOption('where')); self::assertSame('(id IS NULL)', $onlineTable->getIndex('simple_partial_index')->getOption('where')); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 0f37e879ce7..34298665bc6 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -431,7 +431,7 @@ public function testDiffListTableColumns() $comparator = new Comparator(); $diff = $comparator->diffTable($offlineTable, $onlineTable); - self::assertFalse($diff, 'No differences should be detected with the offline vs online schema.'); + self::assertNull($diff, 'No differences should be detected with the offline vs online schema.'); } public function testListTableIndexes() @@ -1308,7 +1308,7 @@ public function testComparatorShouldNotAddCommentToJsonTypeSinceItIsTheDefaultNo $comparator = new Comparator(); $tableDiff = $comparator->diffTable($this->schemaManager->listTableDetails('json_test'), $table); - self::assertFalse($tableDiff); + self::assertNull($tableDiff); } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 1d3143e9dd0..5191bdfb55f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -237,7 +237,7 @@ public function testDiffListIntegerAutoincrementTableColumns($integerType, $unsi if ($expectedComparatorDiff) { self::assertEmpty($this->schemaManager->getDatabasePlatform()->getAlterTableSQL($diff)); } else { - self::assertFalse($diff); + self::assertNull($diff); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php index 460009eff3f..2652d4d4caa 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL202Test.php @@ -20,7 +20,7 @@ protected function setUp() : void $this->markTestSkipped('OCI8 only test'); } - if ($this->connection->getSchemaManager()->tablesExist('DBAL202')) { + if ($this->connection->getSchemaManager()->tableExists('DBAL202')) { $this->connection->exec('DELETE FROM DBAL202'); } else { $table = new Table('DBAL202'); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php index 001c8a3ad71..0d743c950a0 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL510Test.php @@ -37,6 +37,6 @@ public function testSearchPathSchemaChanges() $comparator = new Comparator(); $diff = $comparator->diffTable($onlineTable, $table); - self::assertFalse($diff); + self::assertNull($diff); } } diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index 910bdd31507..f34c8417768 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -453,13 +453,11 @@ public function testCompareSequences() $seq1 = new Sequence('foo', 1, 1); $seq2 = new Sequence('foo', 1, 2); $seq3 = new Sequence('foo', 2, 1); - $seq4 = new Sequence('foo', '1', '1'); $c = new Comparator(); self::assertTrue($c->diffSequence($seq1, $seq2)); self::assertTrue($c->diffSequence($seq1, $seq3)); - self::assertFalse($c->diffSequence($seq1, $seq4)); } public function testRemovedSequence() @@ -622,7 +620,7 @@ public function testCompareColumnCompareCaseInsensitive() $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); - self::assertFalse($tableDiff); + self::assertNull($tableDiff); } public function testCompareIndexBasedOnPropertiesNotName() @@ -659,7 +657,7 @@ public function testCompareForeignKeyBasedOnPropertiesNotName() $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); - self::assertFalse($tableDiff); + self::assertNull($tableDiff); } public function testCompareForeignKeyRestrictNoActionAreTheSame() diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php index 2c862fa4d05..7d1143df360 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableDiffTest.php @@ -58,7 +58,7 @@ public function testReturnsNewName() { $tableDiff = new TableDiff('foo'); - self::assertFalse($tableDiff->getNewName()); + self::assertNull($tableDiff->getNewName()); $tableDiff->newName = 'bar';