Enforced parameter and return value types in event-related classes

parent 1e2d36b2
# Upgrade to 3.0 # 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 ## BC BREAK: Changes in the `Doctrine\DBAL\Connection` API
- The following methods have been removed as leaking internal implementation details: `::getHost()`, `::getPort()`, `::getUsername()`, `::getPassword()`. - The following methods have been removed as leaking internal implementation details: `::getHost()`, `::getPort()`, `::getUsername()`, `::getPassword()`.
......
...@@ -6,9 +6,6 @@ namespace Doctrine\DBAL\Event; ...@@ -6,9 +6,6 @@ namespace Doctrine\DBAL\Event;
use Doctrine\Common\EventArgs; use Doctrine\Common\EventArgs;
use Doctrine\DBAL\Connection; 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. * Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection.
...@@ -23,41 +20,8 @@ class ConnectionEventArgs extends EventArgs ...@@ -23,41 +20,8 @@ class ConnectionEventArgs extends EventArgs
$this->connection = $connection; $this->connection = $connection;
} }
/** public function getConnection() : Connection
* @return Connection
*/
public function getConnection()
{ {
return $this->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; ...@@ -25,7 +25,7 @@ use function implode;
*/ */
class OracleSessionInit implements EventSubscriber class OracleSessionInit implements EventSubscriber
{ {
/** @var string[] */ /** @var array<string, string> */
protected $_defaultSessionVars = [ protected $_defaultSessionVars = [
'NLS_TIME_FORMAT' => 'HH24:MI:SS', 'NLS_TIME_FORMAT' => 'HH24:MI:SS',
'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS', 'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
...@@ -35,17 +35,14 @@ class OracleSessionInit implements EventSubscriber ...@@ -35,17 +35,14 @@ class OracleSessionInit implements EventSubscriber
]; ];
/** /**
* @param string[] $oracleSessionVars * @param array<string, string> $oracleSessionVars
*/ */
public function __construct(array $oracleSessionVars = []) public function __construct(array $oracleSessionVars = [])
{ {
$this->_defaultSessionVars = array_merge($this->_defaultSessionVars, $oracleSessionVars); $this->_defaultSessionVars = array_merge($this->_defaultSessionVars, $oracleSessionVars);
} }
/** public function postConnect(ConnectionEventArgs $args) : void
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
{ {
if (! count($this->_defaultSessionVars)) { if (! count($this->_defaultSessionVars)) {
return; return;
...@@ -67,7 +64,7 @@ class OracleSessionInit implements EventSubscriber ...@@ -67,7 +64,7 @@ class OracleSessionInit implements EventSubscriber
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSubscribedEvents() public function getSubscribedEvents() : array
{ {
return [Events::postConnect]; return [Events::postConnect];
} }
......
...@@ -16,18 +16,12 @@ class SQLSessionInit implements EventSubscriber ...@@ -16,18 +16,12 @@ class SQLSessionInit implements EventSubscriber
/** @var string */ /** @var string */
protected $sql; protected $sql;
/** public function __construct(string $sql)
* @param string $sql
*/
public function __construct($sql)
{ {
$this->sql = $sql; $this->sql = $sql;
} }
/** public function postConnect(ConnectionEventArgs $args) : void
* @return void
*/
public function postConnect(ConnectionEventArgs $args)
{ {
$conn = $args->getConnection(); $conn = $args->getConnection();
$conn->exec($this->sql); $conn->exec($this->sql);
...@@ -36,7 +30,7 @@ class SQLSessionInit implements EventSubscriber ...@@ -36,7 +30,7 @@ class SQLSessionInit implements EventSubscriber
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getSubscribedEvents() public function getSubscribedEvents() : array
{ {
return [Events::postConnect]; return [Events::postConnect];
} }
......
...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use function array_merge; 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. * 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 ...@@ -25,7 +23,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */ /** @var AbstractPlatform */
private $platform; private $platform;
/** @var string[] */ /** @var array<int, string> */
private $sql = []; private $sql = [];
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
...@@ -35,48 +33,35 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs ...@@ -35,48 +33,35 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
$this->platform = $platform; $this->platform = $platform;
} }
/** public function getColumn() : Column
* @return Column
*/
public function getColumn()
{ {
return $this->column; return $this->column;
} }
/** public function getTableDiff() : TableDiff
* @return TableDiff
*/
public function getTableDiff()
{ {
return $this->tableDiff; return $this->tableDiff;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. * @return $this
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
*/ */
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 $this;
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getSql() public function getSql() : array
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use function array_merge; 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. * 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 ...@@ -25,7 +23,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */ /** @var AbstractPlatform */
private $platform; private $platform;
/** @var string[] */ /** @var array<int, string> */
private $sql = []; private $sql = [];
public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform) public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform)
...@@ -35,48 +33,35 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs ...@@ -35,48 +33,35 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
$this->platform = $platform; $this->platform = $platform;
} }
/** public function getColumnDiff() : ColumnDiff
* @return ColumnDiff
*/
public function getColumnDiff()
{ {
return $this->columnDiff; return $this->columnDiff;
} }
/** public function getTableDiff() : TableDiff
* @return TableDiff
*/
public function getTableDiff()
{ {
return $this->tableDiff; return $this->tableDiff;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. * @return $this
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
*/ */
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 $this;
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getSql() public function getSql() : array
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -7,8 +7,6 @@ namespace Doctrine\DBAL\Event; ...@@ -7,8 +7,6 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use function array_merge; 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. * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform.
...@@ -21,7 +19,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs ...@@ -21,7 +19,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */ /** @var AbstractPlatform */
private $platform; private $platform;
/** @var string[] */ /** @var array<int, string> */
private $sql = []; private $sql = [];
public function __construct(TableDiff $tableDiff, AbstractPlatform $platform) public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
...@@ -30,40 +28,30 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs ...@@ -30,40 +28,30 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
$this->platform = $platform; $this->platform = $platform;
} }
/** public function getTableDiff() : TableDiff
* @return TableDiff
*/
public function getTableDiff()
{ {
return $this->tableDiff; return $this->tableDiff;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. * @return $this
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs
*/ */
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 $this;
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getSql() public function getSql() : array
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use function array_merge; 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. * 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 ...@@ -25,7 +23,7 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */ /** @var AbstractPlatform */
private $platform; private $platform;
/** @var string[] */ /** @var array<int, string> */
private $sql = []; private $sql = [];
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform) public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
...@@ -35,48 +33,35 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs ...@@ -35,48 +33,35 @@ class SchemaAlterTableRemoveColumnEventArgs extends SchemaEventArgs
$this->platform = $platform; $this->platform = $platform;
} }
/** public function getColumn() : Column
* @return Column
*/
public function getColumn()
{ {
return $this->column; return $this->column;
} }
/** public function getTableDiff() : TableDiff
* @return TableDiff
*/
public function getTableDiff()
{ {
return $this->tableDiff; return $this->tableDiff;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. * @return $this
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs
*/ */
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 $this;
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getSql() public function getSql() : array
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; ...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Schema\TableDiff;
use function array_merge; 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. * 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 ...@@ -28,13 +26,10 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
/** @var AbstractPlatform */ /** @var AbstractPlatform */
private $platform; private $platform;
/** @var string[] */ /** @var array<int, string> */
private $sql = []; private $sql = [];
/** public function __construct(string $oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
* @param string $oldColumnName
*/
public function __construct($oldColumnName, Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
{ {
$this->oldColumnName = $oldColumnName; $this->oldColumnName = $oldColumnName;
$this->column = $column; $this->column = $column;
...@@ -42,56 +37,40 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs ...@@ -42,56 +37,40 @@ class SchemaAlterTableRenameColumnEventArgs extends SchemaEventArgs
$this->platform = $platform; $this->platform = $platform;
} }
/** public function getOldColumnName() : string
* @return string
*/
public function getOldColumnName()
{ {
return $this->oldColumnName; return $this->oldColumnName;
} }
/** public function getColumn() : Column
* @return Column
*/
public function getColumn()
{ {
return $this->column; return $this->column;
} }
/** public function getTableDiff() : TableDiff
* @return TableDiff
*/
public function getTableDiff()
{ {
return $this->tableDiff; return $this->tableDiff;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. * @return $this
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs
*/ */
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 $this;
} }
/** /**
* @return string[] * @return array<int, string>
*/ */
public function getSql() public function getSql() : array
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -5,7 +5,6 @@ declare(strict_types=1); ...@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Event; namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
/** /**
...@@ -14,12 +13,12 @@ use Doctrine\DBAL\Schema\Column; ...@@ -14,12 +13,12 @@ use Doctrine\DBAL\Schema\Column;
class SchemaColumnDefinitionEventArgs extends SchemaEventArgs class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
{ {
/** @var Column|null */ /** @var Column|null */
private $column = null; private $column;
/** /**
* Raw column data as fetched from the database. * Raw column data as fetched from the database.
* *
* @var mixed[] * @var array<string, mixed>
*/ */
private $tableColumn; private $tableColumn;
...@@ -33,11 +32,9 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs ...@@ -33,11 +32,9 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
private $connection; private $connection;
/** /**
* @param mixed[] $tableColumn * @param array<string, mixed> $tableColumn
* @param string $table
* @param string $database
*/ */
public function __construct(array $tableColumn, $table, $database, Connection $connection) public function __construct(array $tableColumn, string $table, string $database, Connection $connection)
{ {
$this->tableColumn = $tableColumn; $this->tableColumn = $tableColumn;
$this->table = $table; $this->table = $table;
...@@ -49,62 +46,40 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs ...@@ -49,62 +46,40 @@ class SchemaColumnDefinitionEventArgs extends SchemaEventArgs
* Allows to clear the column which means the column will be excluded from * Allows to clear the column which means the column will be excluded from
* tables column list. * 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; $this->column = $column;
return $this; return $this;
} }
/** public function getColumn() : ?Column
* @return Column|null
*/
public function getColumn()
{ {
return $this->column; return $this->column;
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function getTableColumn() public function getTableColumn() : array
{ {
return $this->tableColumn; return $this->tableColumn;
} }
/** public function getTable() : string
* @return string
*/
public function getTable()
{ {
return $this->table; return $this->table;
} }
/** public function getDatabase() : string
* @return string
*/
public function getDatabase()
{ {
return $this->database; return $this->database;
} }
/** public function getConnection() : Connection
* @return Connection
*/
public function getConnection()
{ {
return $this->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; ...@@ -8,8 +8,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use function array_merge; 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. * 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 ...@@ -35,40 +33,27 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
$this->platform = $platform; $this->platform = $platform;
} }
/** public function getColumn() : Column
* @return Column
*/
public function getColumn()
{ {
return $this->column; return $this->column;
} }
/** public function getTable() : Table
* @return Table
*/
public function getTable()
{ {
return $this->table; return $this->table;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. * @return $this
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs
*/ */
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 $this;
} }
...@@ -76,7 +61,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs ...@@ -76,7 +61,7 @@ class SchemaCreateTableColumnEventArgs extends SchemaEventArgs
/** /**
* @return array<int, string> * @return array<int, string>
*/ */
public function getSql() public function getSql() : array
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -7,8 +7,6 @@ namespace Doctrine\DBAL\Event; ...@@ -7,8 +7,6 @@ namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use function array_merge; 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. * Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\AbstractPlatform.
...@@ -18,21 +16,21 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -18,21 +16,21 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
/** @var Table */ /** @var Table */
private $table; private $table;
/** @var mixed[][] */ /** @var array<string, array<string, mixed>> */
private $columns; private $columns;
/** @var mixed[] */ /** @var array<string, mixed> */
private $options; private $options;
/** @var AbstractPlatform */ /** @var AbstractPlatform */
private $platform; private $platform;
/** @var string[] */ /** @var array<int, string> */
private $sql = []; private $sql = [];
/** /**
* @param mixed[][] $columns * @param array<string, array<string, mixed>> $columns
* @param mixed[] $options * @param array<string, mixed> $options
*/ */
public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform) public function __construct(Table $table, array $columns, array $options, AbstractPlatform $platform)
{ {
...@@ -42,48 +40,38 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -42,48 +40,38 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
$this->platform = $platform; $this->platform = $platform;
} }
/** public function getTable() : Table
* @return Table
*/
public function getTable()
{ {
return $this->table; return $this->table;
} }
/** /**
* @return mixed[][] * @return array<string, array<string, mixed>>
*/ */
public function getColumns() public function getColumns() : array
{ {
return $this->columns; return $this->columns;
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function getOptions() public function getOptions() : array
{ {
return $this->options; return $this->options;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* Passing multiple SQL statements as an array is deprecated. Pass each statement as an individual argument instead. * @return $this
*
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaCreateTableEventArgs
*/ */
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 $this;
} }
...@@ -91,7 +79,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs ...@@ -91,7 +79,7 @@ class SchemaCreateTableEventArgs extends SchemaEventArgs
/** /**
* @return array<int, string> * @return array<int, string>
*/ */
public function getSql() public function getSql() : array
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -41,30 +41,22 @@ class SchemaDropTableEventArgs extends SchemaEventArgs ...@@ -41,30 +41,22 @@ class SchemaDropTableEventArgs extends SchemaEventArgs
return $this->table; return $this->table;
} }
/** public function getPlatform() : AbstractPlatform
* @return AbstractPlatform
*/
public function getPlatform()
{ {
return $this->platform; return $this->platform;
} }
/** /**
* @param string $sql * @return $this
*
* @return \Doctrine\DBAL\Event\SchemaDropTableEventArgs
*/ */
public function setSql($sql) public function setSql(string $sql) : self
{ {
$this->sql = $sql; $this->sql = $sql;
return $this; return $this;
} }
/** public function getSql() : ?string
* @return string|null
*/
public function getSql()
{ {
return $this->sql; return $this->sql;
} }
......
...@@ -15,19 +15,16 @@ class SchemaEventArgs extends EventArgs ...@@ -15,19 +15,16 @@ class SchemaEventArgs extends EventArgs
private $preventDefault = false; private $preventDefault = false;
/** /**
* @return \Doctrine\DBAL\Event\SchemaEventArgs * @return $this
*/ */
public function preventDefault() public function preventDefault() : self
{ {
$this->preventDefault = true; $this->preventDefault = true;
return $this; return $this;
} }
/** public function isDefaultPrevented() : bool
* @return bool
*/
public function isDefaultPrevented()
{ {
return $this->preventDefault; return $this->preventDefault;
} }
......
...@@ -5,7 +5,6 @@ declare(strict_types=1); ...@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Doctrine\DBAL\Event; namespace Doctrine\DBAL\Event;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Index;
/** /**
...@@ -14,12 +13,12 @@ use Doctrine\DBAL\Schema\Index; ...@@ -14,12 +13,12 @@ use Doctrine\DBAL\Schema\Index;
class SchemaIndexDefinitionEventArgs extends SchemaEventArgs class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
{ {
/** @var Index|null */ /** @var Index|null */
private $index = null; private $index;
/** /**
* Raw index data as fetched from the database. * Raw index data as fetched from the database.
* *
* @var mixed[] * @var array<string, mixed>
*/ */
private $tableIndex; private $tableIndex;
...@@ -30,10 +29,9 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs ...@@ -30,10 +29,9 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
private $connection; private $connection;
/** /**
* @param mixed[] $tableIndex * @param array<string, mixed> $tableIndex
* @param string $table
*/ */
public function __construct(array $tableIndex, $table, Connection $connection) public function __construct(array $tableIndex, string $table, Connection $connection)
{ {
$this->tableIndex = $tableIndex; $this->tableIndex = $tableIndex;
$this->table = $table; $this->table = $table;
...@@ -43,52 +41,35 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs ...@@ -43,52 +41,35 @@ class SchemaIndexDefinitionEventArgs extends SchemaEventArgs
/** /**
* Allows to clear the index which means the index will be excluded from tables index list. * 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; $this->index = $index;
return $this; return $this;
} }
/** public function getIndex() : ?Index
* @return Index|null
*/
public function getIndex()
{ {
return $this->index; return $this->index;
} }
/** /**
* @return mixed[] * @return array<string, mixed>
*/ */
public function getTableIndex() public function getTableIndex() : array
{ {
return $this->tableIndex; return $this->tableIndex;
} }
/** public function getTable() : string
* @return string
*/
public function getTable()
{ {
return $this->table; return $this->table;
} }
/** public function getConnection() : Connection
* @return Connection
*/
public function getConnection()
{ {
return $this->connection; return $this->connection;
} }
/**
* @return AbstractPlatform
*/
public function getDatabasePlatform()
{
return $this->connection->getDatabasePlatform();
}
} }
...@@ -1345,7 +1345,10 @@ abstract class AbstractPlatform ...@@ -1345,7 +1345,10 @@ abstract class AbstractPlatform
$columnData['primary'] = true; $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)) { 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