Skip to content

Commit

Permalink
Merge pull request #3577 from morozov/event-types
Browse files Browse the repository at this point in the history
Enforced parameter and return value types in event-related classes
  • Loading branch information
morozov committed May 31, 2019
2 parents ab52d69 + 6c90257 commit e571fa1
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 315 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 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()`.
Expand Down
32 changes: 1 addition & 31 deletions lib/Doctrine/DBAL/Event/ConnectionEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

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.
Expand All @@ -23,35 +20,8 @@ public function __construct(Connection $connection)
$this->connection = $connection;
}

/**
* @return Connection
*/
public function getConnection()
public function getConnection() : Connection
{
return $this->connection;
}

/**
* @return Driver
*/
public function getDriver()
{
return $this->connection->getDriver();
}

/**
* @return AbstractPlatform
*/
public function getDatabasePlatform()
{
return $this->connection->getDatabasePlatform();
}

/**
* @return AbstractSchemaManager
*/
public function getSchemaManager()
{
return $this->connection->getSchemaManager();
}
}
11 changes: 4 additions & 7 deletions lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
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',
Expand All @@ -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;
Expand All @@ -67,7 +64,7 @@ public function postConnect(ConnectionEventArgs $args)
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents() : array
{
return [Events::postConnect];
}
Expand Down
12 changes: 3 additions & 9 deletions lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,7 +30,7 @@ public function postConnect(ConnectionEventArgs $args)
/**
* {@inheritdoc}
*/
public function getSubscribedEvents()
public function getSubscribedEvents() : array
{
return [Events::postConnect];
}
Expand Down
34 changes: 9 additions & 25 deletions lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function is_array;

/**
* Event Arguments used when SQL queries for adding table columns are generated inside Doctrine\DBAL\Platform\*Platform.
Expand All @@ -24,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)
Expand All @@ -34,50 +33,35 @@ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatfo
$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;
}

/**
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
if (is_array($sql)) {
$this->sql = array_merge($this->sql, $sql);
} else {
$this->sql[] = $sql;
}
$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;
}
Expand Down
34 changes: 9 additions & 25 deletions lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function is_array;

/**
* Event Arguments used when SQL queries for changing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
Expand All @@ -24,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)
Expand All @@ -34,50 +33,35 @@ public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, Abstra
$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;
}

/**
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
if (is_array($sql)) {
$this->sql = array_merge($this->sql, $sql);
} else {
$this->sql[] = $sql;
}
$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;
}
Expand Down
29 changes: 8 additions & 21 deletions lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\TableDiff;
use function array_merge;
use function is_array;

/**
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform.
Expand All @@ -20,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)
Expand All @@ -29,42 +28,30 @@ public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
$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;
}

/**
* @param string|string[] $sql
*
* @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs
* @return $this
*/
public function addSql($sql)
public function addSql(string ...$sql) : self
{
if (is_array($sql)) {
$this->sql = array_merge($this->sql, $sql);
} else {
$this->sql[] = $sql;
}
$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;
}
Expand Down
Loading

0 comments on commit e571fa1

Please sign in to comment.