Enforced parameter and return value types in event-related classes

parent 1e2d36b2
# Upgrade to 3.0
## BC BREAK: Changes in the `Doctrine\DBAL\Event` API
- `SchemaAlterTableAddColumnEventArgs::addSql()` and the same method in other `SchemaEventArgs`-based classes no longer accept an array of SQL statements. They accept a variadic string.
- `ConnectionEventArgs::getDriver()`, `::getDatabasePlatform()` and `::getSchemaManager()` methods have been removed. The connection information can be obtained from the connection which is available via `::getConnection()`.
- `SchemaColumnDefinitionEventArgs::getDatabasePlatform()` and `SchemaIndexDefinitionEventArgs::getDatabasePlatform()` have been removed for the same reason as above.
## BC BREAK: Changes in the `Doctrine\DBAL\Connection` API
- The following methods have been removed as leaking internal implementation details: `::getHost()`, `::getPort()`, `::getUsername()`, `::getPassword()`.
......
......@@ -6,9 +6,6 @@ namespace Doctrine\DBAL\Event;
use Doctrine\Common\EventArgs;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
/**
* Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection.
......@@ -23,41 +20,8 @@ class ConnectionEventArgs extends EventArgs
$this->connection = $connection;
}
/**
* @return Connection
*/
public function getConnection()
public function getConnection() : Connection
{
return $this->connection;
}
/**
* @deprecated Use ConnectionEventArgs::getConnection() and Connection::getDriver() instead.
*
* @return Driver
*/
public function getDriver()
{
return $this->connection->getDriver();
}
/**
* @deprecated Use ConnectionEventArgs::getConnection() and Connection::getDatabasePlatform() instead.
*
* @return AbstractPlatform
*/
public function getDatabasePlatform()
{
return $this->connection->getDatabasePlatform();
}
/**
* @deprecated Use ConnectionEventArgs::getConnection() and Connection::getSchemaManager() instead.
*
* @return AbstractSchemaManager
*/
public function getSchemaManager()
{
return $this->connection->getSchemaManager();
}
}
......@@ -25,7 +25,7 @@ use function implode;
*/
class OracleSessionInit implements EventSubscriber
{
/** @var string[] */
/** @var array<string, string> */
protected $_defaultSessionVars = [
'NLS_TIME_FORMAT' => 'HH24:MI:SS',
'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
......@@ -35,17 +35,14 @@ class OracleSessionInit implements EventSubscriber
];
/**
* @param string[] $oracleSessionVars
* @param array<string, string> $oracleSessionVars
*/
public function __construct(array $oracleSessionVars = [])
{
$this->_defaultSessionVars = array_merge($this->_defaultSessionVars, $oracleSessionVars);
}
/**
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
public function postConnect(ConnectionEventArgs $args) : void
{
if (! count($this->_defaultSessionVars)) {
return;
......@@ -67,7 +64,7 @@ class OracleSessionInit implements EventSubscriber
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents() : array
{
return [Events::postConnect];
}
......
......@@ -16,18 +16,12 @@ class SQLSessionInit implements EventSubscriber
/** @var string */
protected $sql;
/**
* @param string $sql
*/
public function __construct($sql)
public function __construct(string $sql)
{
$this->sql = $sql;
}
/**
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
public function postConnect(ConnectionEventArgs $args) : void
{
$conn = $args->getConnection();
$conn->exec($this->sql);
......@@ -36,7 +30,7 @@ class SQLSessionInit implements EventSubscriber
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents() : array
{
return [Events::postConnect];
}
......
......@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
/**
* Event Arguments used when SQL queries for adding table columns are generated inside Doctrine\DBAL\Platform\*Platform.
......@@ -25,7 +23,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */
private $platform;
/** @var string[] */
/** @var array<int, string> */
private $sql = [];
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
......@@ -35,48 +33,35 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
$this->platform = $platform;
}
/**
* @return Column
*/
public function getColumn()
public function getColumn() : Column
{
return $this->column;
}
/**
* @return TableDiff
*/
public function getTableDiff()
public function getTableDiff() : TableDiff
{
return $this->tableDiff;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
$this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
$this->sql = array_merge($this->sql, $sql);
return $this;
}
/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
public function getSql() : array
{
return $this->sql;
}
......
......@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
/**
* Event Arguments used when SQL queries for changing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
......@@ -25,7 +23,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */
private $platform;
/** @var string[] */
/** @var array<int, string> */
private $sql = [];
public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform)
......@@ -35,48 +33,35 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
$this->platform = $platform;
}
/**
* @return ColumnDiff
*/
public function getColumnDiff()
public function getColumnDiff() : ColumnDiff
{
return $this->columnDiff;
}
/**
* @return TableDiff
*/
public function getTableDiff()
public function getTableDiff() : TableDiff
{
return $this->tableDiff;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
$this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
$this->sql = array_merge($this->sql, $sql);
return $this;
}
/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
public function getSql() : array
{
return $this->sql;
}
......
......@@ -7,8 +7,6 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
/**
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform.
......@@ -21,7 +19,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */
private $platform;
/** @var string[] */
/** @var array<int, string> */
private $sql = [];
public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
......@@ -30,40 +28,30 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
$this->platform = $platform;
}
/**
* @return TableDiff
*/
public function getTableDiff()
public function getTableDiff() : TableDiff
{
return $this->tableDiff;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
$this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
$this->sql = array_merge($this->sql, $sql);
return $this;
}
/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
public function getSql() : array
{
return $this->sql;
}
......
......@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
/**
* Event Arguments used when SQL queries for removing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
......@@ -25,7 +23,7 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */
private $platform;
/** @var string[] */
/** @var array<int, string> */
private $sql = [];
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
......@@ -35,48 +33,35 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
$this->platform = $platform;
}
/**
* @return Column
*/
public function getColumn()
public function getColumn() : Column
{
return $this->column;
}
/**
* @return TableDiff
*/
public function getTableDiff()
public function getTableDiff() : TableDiff
{
return $this->tableDiff;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
$this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
$this->sql = array_merge($this->sql, $sql);
return $this;
}
/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
public function getSql() : array
{
return $this->sql;
}
......
......@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function func_get_args;
use function is_array;
/**
* Event Arguments used when SQL queries for renaming table columns are generated inside Doctrine\DBAL\Platform\*Platform.
......@@ -28,13 +26,10 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */
private $platform;
/** @var string[] */
/** @var array<int, string> */
private $sql = [];
/**
* @param string $oldColumnName
*/
public function __construct($oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
public function __construct(string $oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{
$this->oldColumnName = $oldColumnName;
$this->column = $column;
......@@ -42,56 +37,40 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
$this->platform = $platform;
}
/**
* @return string
*/
public function getOldColumnName()
public function getOldColumnName() : string
{
return $this->oldColumnName;
}
/**
* @return Column
*/
public function getColumn()
public function getColumn() : Column
{
return $this->column;
}
/**
* @return TableDiff
*/
public function getTableDiff()
public function getTableDiff() : TableDiff
{
return $this->tableDiff;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
$this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
$this->sql = array_merge($this->sql, $sql);
return $this;
}
/**
* @return string[]
* @return array<int, string>
*/
public function getSql()
public function getSql() : array
{
return $this->sql;
}
......
......@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
/**
......@@ -14,12 +13,12 @@ use Doctrine\DBAL\Schema\Column;
class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
{
/** @var Column|null */
private $column = null;
private $column;
/**
* Raw column data as fetched from the database.
*
* @var mixed[]
* @var array<string, mixed>
*/
private $tableColumn;
......@@ -33,11 +32,9 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
private $connection;
/**
* @param mixed[] $tableColumn
* @param string $table
* @param string $database
* @param array<string, mixed> $tableColumn
*/
public function __construct(array $tableColumn, $table, $database, Connection $connection)
public function __construct(array $tableColumn, string $table, string $database, Connection $connection)
{
$this->tableColumn = $tableColumn;
$this->table = $table;
......@@ -49,62 +46,40 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
* Allows to clear the column which means the column will be excluded from
* tables column list.
*
* @return \Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs
* @return $this
*/
public function setColumn(?Column $column = null)
public function setColumn(?Column $column) : self
{
$this->column = $column;
return $this;
}
/**
* @return Column|null
*/
public function getColumn()
public function getColumn() : ?Column
{
return $this->column;
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getTableColumn()
public function getTableColumn() : array
{
return $this->tableColumn;
}
/**
* @return string
*/
public function getTable()
public function getTable() : string
{
return $this->table;
}
/**
* @return string
*/
public function getDatabase()
public function getDatabase() : string
{
return $this->database;
}
/**
* @return Connection
*/
public function getConnection()
public function getConnection() : Connection
{
return $this->connection;
}
/**
* @deprecated Use SchemaColumnDefinitionEventArgs::getConnection() and Connection::getDatabasePlatform() instead.
*
* @return AbstractPlatform
*/
public function getDatabasePlatform()
{
return $this->connection->getDatabasePlatform();
}
}
......@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
use function func_get_args;
use function is_array;
/**
* Event Arguments used when SQL queries for creating table columns are generated inside Doctrine\DBAL\Platform\AbstractPlatform.
......@@ -35,40 +33,27 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
$this->platform = $platform;
}
/**
* @return Column
*/
public function getColumn()
public function getColumn() : Column
{
return $this->column;
}
/**
* @return Table
*/
public function getTable()
public function getTable() : Table
{
return $this->table;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
$this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
$this->sql = array_merge($this->sql, $sql);
return $this;
}
......@@ -76,7 +61,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
/**
* @return array<int, string>
*/
public function getSql()
public function getSql() : array
{
return $this->sql;
}
......
......@@ -7,8 +7,6 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Table;
use function array_merge;
use function func_get_args;
use function is_array;
/**
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform.
......@@ -18,21 +16,21 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
/** @var Table */
private $table;
/** @var mixed[][] */
/** @var array<string, array<string, mixed>> */
private $columns;
/** @var mixed[] */
/** @var array<string, mixed> */
private $options;
/** @var AbstractPlatform */
private $platform;
/** @var string[] */
/** @var array<int, string> */
private $sql = [];
/**
* @param mixed[][] $columns
* @param mixed[] $options
* @param array<string, array<string, mixed>> $columns
* @param array<string, mixed> $options
*/
public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
{
......@@ -42,48 +40,38 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
$this->platform = $platform;
}
/**
* @return Table
*/
public function getTable()
public function getTable() : Table
{
return $this->table;
}
/**
* @return mixed[][]
* @return array<string, array<string, mixed>>
*/
public function getColumns()
public function getColumns() : array
{
return $this->columns;
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getOptions()
public function getOptions() : array
{
return $this->options;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead.
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaCreateTableEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
$this->sql = array_merge($this->sql, is_array($sql) ? $sql : func_get_args());
$this->sql = array_merge($this->sql, $sql);
return $this;
}
......@@ -91,7 +79,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
/**
* @return array<int, string>
*/
public function getSql()
public function getSql() : array
{
return $this->sql;
}
......
......@@ -41,30 +41,22 @@ class SchemaDropTableEventArgs extends SchemaEventArgs
return $this->table;
}
/**
* @return AbstractPlatform
*/
public function getPlatform()
public function getPlatform() : AbstractPlatform
{
return $this->platform;
}
/**
* @param string $sql
*
* @return \Doctrine\DBAL\Event\SchemaDropTableEventArgs
* @return $this
*/
public function setSql($sql)
public function setSql(string $sql) : self
{
$this->sql = $sql;
return $this;
}
/**
* @return string|null
*/
public function getSql()
public function getSql() : ?string
{
return $this->sql;
}
......
......@@ -15,19 +15,16 @@ class SchemaEventArgs extends EventArgs
private $preventDefault = false;
/**
* @return \Doctrine\DBAL\Event\SchemaEventArgs
* @return $this
*/
public function preventDefault()
public function preventDefault() : self
{
$this->preventDefault = true;
return $this;
}
/**
* @return bool
*/
public function isDefaultPrevented()
public function isDefaultPrevented() : bool
{
return $this->preventDefault;
}
......
......@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Index;
/**
......@@ -14,12 +13,12 @@ use Doctrine\DBAL\Schema\Index;
class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
{
/** @var Index|null */
private $index = null;
private $index;
/**
* Raw index data as fetched from the database.
*
* @var mixed[]
* @var array<string, mixed>
*/
private $tableIndex;
......@@ -30,10 +29,9 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
private $connection;
/**
* @param mixed[] $tableIndex
* @param string $table
* @param array<string, mixed> $tableIndex
*/
public function __construct(array $tableIndex, $table, Connection $connection)
public function __construct(array $tableIndex, string $table, Connection $connection)
{
$this->tableIndex = $tableIndex;
$this->table = $table;
......@@ -43,52 +41,35 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
/**
* Allows to clear the index which means the index will be excluded from tables index list.
*
* @return SchemaIndexDefinitionEventArgs
* @return $this
*/
public function setIndex(?Index $index = null)
public function setIndex(?Index $index) : self
{
$this->index = $index;
return $this;
}
/**
* @return Index|null
*/
public function getIndex()
public function getIndex() : ?Index
{
return $this->index;
}
/**
* @return mixed[]
* @return array<string, mixed>
*/
public function getTableIndex()
public function getTableIndex() : array
{
return $this->tableIndex;
}
/**
* @return string
*/
public function getTable()
public function getTable() : string
{
return $this->table;
}
/**
* @return Connection
*/
public function getConnection()
public function getConnection() : Connection
{
return $this->connection;
}
/**
* @return AbstractPlatform
*/
public function getDatabasePlatform()
{
return $this->connection->getDatabasePlatform();
}
}
......@@ -1345,7 +1345,10 @@ abstract class AbstractPlatform
$columnData['primary'] = true;
}
$columns[$columnData['name']] = $columnData;
$columnName = $columnData['name'];
assert(is_string($columnName));
$columns[$columnName] = $columnData;
}
if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment