diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 3de03f1fdbb..eab459a7e16 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -62,11 +62,11 @@ public function __construct(Connection $connection, AbstractPlatform $platform) */ public function listDatabases(): array { - $sql = $this->_platform->getListDatabasesSQL(); - - $databases = $this->_conn->fetchAllAssociative($sql); - - return $this->_getPortableDatabasesList($databases); + return array_map(function (array $row): string { + return $this->_getPortableDatabaseDefinition($row); + }, $this->_conn->fetchAllAssociative( + $this->_platform->getListDatabasesSQL() + )); } /** @@ -90,13 +90,15 @@ public function listSchemaNames(): array */ public function listSequences(): array { - $database = $this->getDatabase(__METHOD__); - - $sql = $this->_platform->getListSequencesSQL($database); - - $sequences = $this->_conn->fetchAllAssociative($sql); - - return $this->filterAssetNames($this->_getPortableSequencesList($sequences)); + return $this->filterAssetNames( + array_map(function (array $row): Sequence { + return $this->_getPortableSequenceDefinition($row); + }, $this->_conn->fetchAllAssociative( + $this->_platform->getListSequencesSQL( + $this->getDatabase(__METHOD__) + ) + )) + ); } /** @@ -175,13 +177,12 @@ public function tableExists(string $tableName): bool */ public function listTableNames(): array { - $database = $this->getDatabase(__METHOD__); - return $this->filterAssetNames( - $this->_getPortableTablesList( - $this->selectTableNames($database) - ->fetchAllAssociative() - ) + array_map(function (array $row): string { + return $this->_getPortableTableDefinition($row); + }, $this->selectTableNames( + $this->getDatabase(__METHOD__) + )->fetchAllAssociative()) ); } @@ -193,7 +194,7 @@ public function listTableNames(): array * * @return array */ - protected function filterAssetNames(array $assetNames): array + private function filterAssetNames(array $assetNames): array { $filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter(); if ($filter === null) { @@ -348,18 +349,19 @@ abstract protected function fetchTableOptionsByTable(string $databaseName, ?stri /** * Lists the views this connection has. * - * @return array + * @return list * * @throws Exception */ public function listViews(): array { - $database = $this->getDatabase(__METHOD__); - - $sql = $this->_platform->getListViewsSQL($database); - $views = $this->_conn->fetchAllAssociative($sql); - - return $this->_getPortableViewsList($views); + return array_map(function (array $row): View { + return $this->_getPortableViewDefinition($row); + }, $this->_conn->fetchAllAssociative( + $this->_platform->getListViewsSQL( + $this->getDatabase(__METHOD__) + ) + )); } /** @@ -612,47 +614,14 @@ public function renameTable(string $name, string $newName): void * the native DBMS data definition to a portable Doctrine definition */ - /** - * @param array $databases - * - * @return array - */ - protected function _getPortableDatabasesList(array $databases): array - { - $list = []; - foreach ($databases as $value) { - $list[] = $this->_getPortableDatabaseDefinition($value); - } - - return $list; - } - /** * @param array $database - */ - protected function _getPortableDatabaseDefinition(array $database): string - { - assert(! empty($database)); - - return array_shift($database); - } - - /** - * @param array> $sequences - * - * @return array * * @throws Exception */ - protected function _getPortableSequencesList(array $sequences): array + protected function _getPortableDatabaseDefinition(array $database): string { - $list = []; - - foreach ($sequences as $value) { - $list[] = $this->_getPortableSequenceDefinition($value); - } - - return $list; + throw NotSupported::new(__METHOD__); } /** @@ -796,55 +765,17 @@ protected function _getPortableTableIndexesList(array $tableIndexes, string $tab return $indexes; } - /** - * @param array> $tables - * - * @return array - */ - protected function _getPortableTablesList(array $tables): array - { - $list = []; - foreach ($tables as $value) { - $list[] = $this->_getPortableTableDefinition($value); - } - - return $list; - } - /** * @param array $table */ - protected function _getPortableTableDefinition(array $table): string - { - assert(! empty($table)); - - return array_shift($table); - } - - /** - * @param array> $views - * - * @return array - */ - protected function _getPortableViewsList(array $views): array - { - $list = []; - foreach ($views as $value) { - $view = $this->_getPortableViewDefinition($value); - $name = strtolower($view->getQuotedName($this->_platform)); - $list[$name] = $view; - } - - return $list; - } + abstract protected function _getPortableTableDefinition(array $table): string; /** * @param array $view + * + * @abstract */ - protected function _getPortableViewDefinition(array $view): View - { - throw NotSupported::new('Views'); - } + abstract protected function _getPortableViewDefinition(array $view): View; /** * @param array> $tableForeignKeys diff --git a/src/Schema/MySQLSchemaManager.php b/src/Schema/MySQLSchemaManager.php index bf61c3e773e..205dbb6a4b1 100644 --- a/src/Schema/MySQLSchemaManager.php +++ b/src/Schema/MySQLSchemaManager.php @@ -50,6 +50,14 @@ class MySQLSchemaManager extends AbstractSchemaManager "''" => "'", ]; + /** + * {@inheritdoc} + */ + protected function _getPortableTableDefinition(array $table): string + { + return $table['TABLE_NAME']; + } + /** * {@inheritdoc} */ diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index f3ce9874528..d0e68ede65e 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -107,9 +107,11 @@ private function hasElementWithName(array $items, string $name): bool } /** - * @param AbstractAsset[] $items + * @param T[] $items + * + * @return T[] * - * @return AbstractAsset[] + * @template T of AbstractAsset */ private function filterElementsByName(array $items, string $name): array { @@ -671,8 +673,7 @@ public function testCreateAndListViews(): void $filtered = array_values($this->filterElementsByName($views, $name)); self::assertCount(1, $filtered); - $viewKey = strtolower($filtered[0]->getName()); - self::assertStringContainsString('view_test_table', $views[$viewKey]->getSql()); + self::assertStringContainsString('view_test_table', $filtered[0]->getSql()); } public function testAutoincrementDetection(): void