Skip to content

Commit

Permalink
Fix type which caused widening of type in Doctrine\DBAL\Event\SchemaC…
Browse files Browse the repository at this point in the history
…olumnDefinitionEventArgs
  • Loading branch information
jwage committed May 29, 2019
1 parent cbe4869 commit 35adcbe
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getDatabase(Connection $conn) : ?string
{
$params = $conn->getParams();

return $params['path'] ?? null;
return $params['path'] ?? '';
}

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Event/SchemaColumnDefinitionEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
private $connection;

/**
* @param mixed[] $tableColumn
* @param string $table
* @param string|null $database
* @param mixed[] $tableColumn
* @param string $table
* @param string $database
*/
public function __construct(array $tableColumn, $table, $database, Connection $connection)
{
Expand Down
34 changes: 24 additions & 10 deletions lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\Exception\NotSupported;
use InvalidArgumentException;
use Throwable;
use function array_filter;
use function array_intersect;
Expand Down Expand Up @@ -128,9 +129,10 @@ public function listNamespaceNames() : array
*/
public function listSequences(?string $database = null) : array
{
if ($database === null) {
$database = $this->_conn->getDatabase();
}
$database = $this->ensureDatabase(
$database ?? $this->_conn->getDatabase()
);

$sql = $this->_platform->getListSequencesSQL($database);

$sequences = $this->_conn->fetchAll($sql);
Expand All @@ -152,9 +154,9 @@ public function listSequences(?string $database = null) : array
*/
public function listTableColumns(string $table, ?string $database = null) : array
{
if (! $database) {
$database = $this->_conn->getDatabase();
}
$database = $this->ensureDatabase(
$database ?? $this->_conn->getDatabase()
);

$sql = $this->_platform->getListTableColumnsSQL($table, $database);

Expand Down Expand Up @@ -267,9 +269,12 @@ public function listTableDetails(string $tableName) : Table
*/
public function listViews() : array
{
$database = $this->_conn->getDatabase();
$sql = $this->_platform->getListViewsSQL($database);
$views = $this->_conn->fetchAll($sql);
$database = $this->ensureDatabase(
$this->_conn->getDatabase()
);

$sql = $this->_platform->getListViewsSQL($database);
$views = $this->_conn->fetchAll($sql);

return $this->_getPortableViewsList($views);
}
Expand Down Expand Up @@ -661,7 +666,7 @@ protected function _getPortableSequenceDefinition(array $sequence) : Sequence
*
* @return array<string, Column>
*/
protected function _getPortableTableColumnList(string $table, ?string $database, array $tableColumns) : array
protected function _getPortableTableColumnList(string $table, string $database, array $tableColumns) : array
{
$eventManager = $this->_platform->getEventManager();

Expand Down Expand Up @@ -973,4 +978,13 @@ final protected function extractDoctrineTypeFromComment(?string &$comment) : ?st

return $match[2];
}

private function ensureDatabase(?string $database) : string
{
if ($database === null) {
throw new InvalidArgumentException('Needs a database.');
}

return $database;
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ protected function _getPortableTableIndexesList(array $tableIndexRows, string $t
/**
* {@inheritdoc}
*/
protected function _getPortableTableColumnList(string $table, ?string $database, array $tableColumns) : array
protected function _getPortableTableColumnList(string $table, string $database, array $tableColumns) : array
{
$list = parent::_getPortableTableColumnList($table, $database, $tableColumns);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ abstract protected function createDriver();

protected static function getDatabaseNameForConnectionWithoutDatabaseNameParameter() : ?string
{
return null;
return '';
}
}

0 comments on commit 35adcbe

Please sign in to comment.