Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-public API cleanup in AbstractSchemaManager #5456

Merged
merged 5 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 34 additions & 103 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
));
}

/**
Expand All @@ -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__)
)
))
);
}

/**
Expand Down Expand Up @@ -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())
);
}

Expand All @@ -193,7 +194,7 @@ public function listTableNames(): array
*
* @return array<int, mixed>
*/
protected function filterAssetNames(array $assetNames): array
private function filterAssetNames(array $assetNames): array
{
$filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter();
if ($filter === null) {
Expand Down Expand Up @@ -348,18 +349,19 @@ abstract protected function fetchTableOptionsByTable(string $databaseName, ?stri
/**
* Lists the views this connection has.
*
* @return array<string, View>
* @return list<View>
*
* @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__)
)
));
}

/**
Expand Down Expand Up @@ -612,47 +614,14 @@ public function renameTable(string $name, string $newName): void
* the native DBMS data definition to a portable Doctrine definition
*/

/**
* @param array<int, mixed> $databases
*
* @return array<int, string>
*/
protected function _getPortableDatabasesList(array $databases): array
{
$list = [];
foreach ($databases as $value) {
$list[] = $this->_getPortableDatabaseDefinition($value);
}

return $list;
}

/**
* @param array<string, string> $database
*/
protected function _getPortableDatabaseDefinition(array $database): string
{
assert(! empty($database));

return array_shift($database);
}

/**
* @param array<int, array<string, mixed>> $sequences
*
* @return array<int, Sequence>
*
* @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__);
}

/**
Expand Down Expand Up @@ -796,55 +765,17 @@ protected function _getPortableTableIndexesList(array $tableIndexes, string $tab
return $indexes;
}

/**
* @param array<int, array<string, mixed>> $tables
*
* @return array<int, string>
*/
protected function _getPortableTablesList(array $tables): array
{
$list = [];
foreach ($tables as $value) {
$list[] = $this->_getPortableTableDefinition($value);
}

return $list;
}

/**
* @param array<string, string> $table
*/
protected function _getPortableTableDefinition(array $table): string
{
assert(! empty($table));

return array_shift($table);
}

/**
* @param array<int, array<string, mixed>> $views
*
* @return array<string, View>
*/
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<string, mixed> $view
*
* @abstract
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this @abstract should be removed now that it is natively abstract

*/
protected function _getPortableViewDefinition(array $view): View
{
throw NotSupported::new('Views');
}
abstract protected function _getPortableViewDefinition(array $view): View;

/**
* @param array<int|string, array<string, mixed>> $tableForeignKeys
Expand Down
8 changes: 8 additions & 0 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ class MySQLSchemaManager extends AbstractSchemaManager
"''" => "'",
];

/**
* {@inheritdoc}
*/
protected function _getPortableTableDefinition(array $table): string
{
return $table['TABLE_NAME'];
}

/**
* {@inheritdoc}
*/
Expand Down
9 changes: 5 additions & 4 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down