Skip to content

Commit e571fa1

Browse files
committed
Merge pull request #3577 from morozov/event-types
Enforced parameter and return value types in event-related classes
2 parents ab52d69 + 6c90257 commit e571fa1

16 files changed

+118
-315
lines changed

UPGRADE.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: Changes in the `Doctrine\DBAL\Event` API
4+
5+
- `SchemaAlterTableAddColumnEventArgs::addSql()` and the same method in other `SchemaEventArgs`-based classes no longer accept an array of SQL statements. They accept a variadic string.
6+
- `ConnectionEventArgs::getDriver()`, `::getDatabasePlatform()` and `::getSchemaManager()` methods have been removed. The connection information can be obtained from the connection which is available via `::getConnection()`.
7+
- `SchemaColumnDefinitionEventArgs::getDatabasePlatform()` and `SchemaIndexDefinitionEventArgs::getDatabasePlatform()` have been removed for the same reason as above.
8+
39
## BC BREAK: Changes in the `Doctrine\DBAL\Connection` API
410

511
- The following methods have been removed as leaking internal implementation details: `::getHost()`, `::getPort()`, `::getUsername()`, `::getPassword()`.

lib/Doctrine/DBAL/Event/ConnectionEventArgs.php

+1-31
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
use Doctrine\Common\EventArgs;
88
use Doctrine\DBAL\Connection;
9-
use Doctrine\DBAL\Driver;
10-
use Doctrine\DBAL\Platforms\AbstractPlatform;
11-
use Doctrine\DBAL\Schema\AbstractSchemaManager;
129

1310
/**
1411
* Event Arguments used when a Driver connection is established inside Doctrine\DBAL\Connection.
@@ -23,35 +20,8 @@ public function __construct(Connection $connection)
2320
$this->connection = $connection;
2421
}
2522

26-
/**
27-
* @return Connection
28-
*/
29-
public function getConnection()
23+
public function getConnection() : Connection
3024
{
3125
return $this->connection;
3226
}
33-
34-
/**
35-
* @return Driver
36-
*/
37-
public function getDriver()
38-
{
39-
return $this->connection->getDriver();
40-
}
41-
42-
/**
43-
* @return AbstractPlatform
44-
*/
45-
public function getDatabasePlatform()
46-
{
47-
return $this->connection->getDatabasePlatform();
48-
}
49-
50-
/**
51-
* @return AbstractSchemaManager
52-
*/
53-
public function getSchemaManager()
54-
{
55-
return $this->connection->getSchemaManager();
56-
}
5727
}

lib/Doctrine/DBAL/Event/Listeners/OracleSessionInit.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626
class OracleSessionInit implements EventSubscriber
2727
{
28-
/** @var string[] */
28+
/** @var array<string, string> */
2929
protected $_defaultSessionVars = [
3030
'NLS_TIME_FORMAT' => 'HH24:MI:SS',
3131
'NLS_DATE_FORMAT' => 'YYYY-MM-DD HH24:MI:SS',
@@ -35,17 +35,14 @@ class OracleSessionInit implements EventSubscriber
3535
];
3636

3737
/**
38-
* @param string[] $oracleSessionVars
38+
* @param array<string, string> $oracleSessionVars
3939
*/
4040
public function __construct(array $oracleSessionVars = [])
4141
{
4242
$this->_defaultSessionVars = array_merge($this->_defaultSessionVars, $oracleSessionVars);
4343
}
4444

45-
/**
46-
* @return void
47-
*/
48-
public function postConnect(ConnectionEventArgs $args)
45+
public function postConnect(ConnectionEventArgs $args) : void
4946
{
5047
if (! count($this->_defaultSessionVars)) {
5148
return;
@@ -67,7 +64,7 @@ public function postConnect(ConnectionEventArgs $args)
6764
/**
6865
* {@inheritdoc}
6966
*/
70-
public function getSubscribedEvents()
67+
public function getSubscribedEvents() : array
7168
{
7269
return [Events::postConnect];
7370
}

lib/Doctrine/DBAL/Event/Listeners/SQLSessionInit.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,12 @@ class SQLSessionInit implements EventSubscriber
1616
/** @var string */
1717
protected $sql;
1818

19-
/**
20-
* @param string $sql
21-
*/
22-
public function __construct($sql)
19+
public function __construct(string $sql)
2320
{
2421
$this->sql = $sql;
2522
}
2623

27-
/**
28-
* @return void
29-
*/
30-
public function postConnect(ConnectionEventArgs $args)
24+
public function postConnect(ConnectionEventArgs $args) : void
3125
{
3226
$conn = $args->getConnection();
3327
$conn->exec($this->sql);
@@ -36,7 +30,7 @@ public function postConnect(ConnectionEventArgs $args)
3630
/**
3731
* {@inheritdoc}
3832
*/
39-
public function getSubscribedEvents()
33+
public function getSubscribedEvents() : array
4034
{
4135
return [Events::postConnect];
4236
}

lib/Doctrine/DBAL/Event/SchemaAlterTableAddColumnEventArgs.php

+9-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Doctrine\DBAL\Schema\Column;
99
use Doctrine\DBAL\Schema\TableDiff;
1010
use function array_merge;
11-
use function is_array;
1211

1312
/**
1413
* Event Arguments used when SQL queries for adding table columns are generated inside Doctrine\DBAL\Platform\*Platform.
@@ -24,7 +23,7 @@ class SchemaAlterTableAddColumnEventArgs extends SchemaEventArgs
2423
/** @var AbstractPlatform */
2524
private $platform;
2625

27-
/** @var string[] */
26+
/** @var array<int, string> */
2827
private $sql = [];
2928

3029
public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatform $platform)
@@ -34,50 +33,35 @@ public function __construct(Column $column, TableDiff $tableDiff, AbstractPlatfo
3433
$this->platform = $platform;
3534
}
3635

37-
/**
38-
* @return Column
39-
*/
40-
public function getColumn()
36+
public function getColumn() : Column
4137
{
4238
return $this->column;
4339
}
4440

45-
/**
46-
* @return TableDiff
47-
*/
48-
public function getTableDiff()
41+
public function getTableDiff() : TableDiff
4942
{
5043
return $this->tableDiff;
5144
}
5245

53-
/**
54-
* @return AbstractPlatform
55-
*/
56-
public function getPlatform()
46+
public function getPlatform() : AbstractPlatform
5747
{
5848
return $this->platform;
5949
}
6050

6151
/**
62-
* @param string|string[] $sql
63-
*
64-
* @return \Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs
52+
* @return $this
6553
*/
66-
public function addSql($sql)
54+
public function addSql(string ...$sql) : self
6755
{
68-
if (is_array($sql)) {
69-
$this->sql = array_merge($this->sql, $sql);
70-
} else {
71-
$this->sql[] = $sql;
72-
}
56+
$this->sql = array_merge($this->sql, $sql);
7357

7458
return $this;
7559
}
7660

7761
/**
78-
* @return string[]
62+
* @return array<int, string>
7963
*/
80-
public function getSql()
64+
public function getSql() : array
8165
{
8266
return $this->sql;
8367
}

lib/Doctrine/DBAL/Event/SchemaAlterTableChangeColumnEventArgs.php

+9-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Doctrine\DBAL\Schema\ColumnDiff;
99
use Doctrine\DBAL\Schema\TableDiff;
1010
use function array_merge;
11-
use function is_array;
1211

1312
/**
1413
* Event Arguments used when SQL queries for changing table columns are generated inside Doctrine\DBAL\Platform\*Platform.
@@ -24,7 +23,7 @@ class SchemaAlterTableChangeColumnEventArgs extends SchemaEventArgs
2423
/** @var AbstractPlatform */
2524
private $platform;
2625

27-
/** @var string[] */
26+
/** @var array<int, string> */
2827
private $sql = [];
2928

3029
public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, AbstractPlatform $platform)
@@ -34,50 +33,35 @@ public function __construct(ColumnDiff $columnDiff, TableDiff $tableDiff, Abstra
3433
$this->platform = $platform;
3534
}
3635

37-
/**
38-
* @return ColumnDiff
39-
*/
40-
public function getColumnDiff()
36+
public function getColumnDiff() : ColumnDiff
4137
{
4238
return $this->columnDiff;
4339
}
4440

45-
/**
46-
* @return TableDiff
47-
*/
48-
public function getTableDiff()
41+
public function getTableDiff() : TableDiff
4942
{
5043
return $this->tableDiff;
5144
}
5245

53-
/**
54-
* @return AbstractPlatform
55-
*/
56-
public function getPlatform()
46+
public function getPlatform() : AbstractPlatform
5747
{
5848
return $this->platform;
5949
}
6050

6151
/**
62-
* @param string|string[] $sql
63-
*
64-
* @return \Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs
52+
* @return $this
6553
*/
66-
public function addSql($sql)
54+
public function addSql(string ...$sql) : self
6755
{
68-
if (is_array($sql)) {
69-
$this->sql = array_merge($this->sql, $sql);
70-
} else {
71-
$this->sql[] = $sql;
72-
}
56+
$this->sql = array_merge($this->sql, $sql);
7357

7458
return $this;
7559
}
7660

7761
/**
78-
* @return string[]
62+
* @return array<int, string>
7963
*/
80-
public function getSql()
64+
public function getSql() : array
8165
{
8266
return $this->sql;
8367
}

lib/Doctrine/DBAL/Event/SchemaAlterTableEventArgs.php

+8-21
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Doctrine\DBAL\Platforms\AbstractPlatform;
88
use Doctrine\DBAL\Schema\TableDiff;
99
use function array_merge;
10-
use function is_array;
1110

1211
/**
1312
* Event Arguments used when SQL queries for creating tables are generated inside Doctrine\DBAL\Platform\*Platform.
@@ -20,7 +19,7 @@ class SchemaAlterTableEventArgs extends SchemaEventArgs
2019
/** @var AbstractPlatform */
2120
private $platform;
2221

23-
/** @var string[] */
22+
/** @var array<int, string> */
2423
private $sql = [];
2524

2625
public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
@@ -29,42 +28,30 @@ public function __construct(TableDiff $tableDiff, AbstractPlatform $platform)
2928
$this->platform = $platform;
3029
}
3130

32-
/**
33-
* @return TableDiff
34-
*/
35-
public function getTableDiff()
31+
public function getTableDiff() : TableDiff
3632
{
3733
return $this->tableDiff;
3834
}
3935

40-
/**
41-
* @return AbstractPlatform
42-
*/
43-
public function getPlatform()
36+
public function getPlatform() : AbstractPlatform
4437
{
4538
return $this->platform;
4639
}
4740

4841
/**
49-
* @param string|string[] $sql
50-
*
51-
* @return \Doctrine\DBAL\Event\SchemaAlterTableEventArgs
42+
* @return $this
5243
*/
53-
public function addSql($sql)
44+
public function addSql(string ...$sql) : self
5445
{
55-
if (is_array($sql)) {
56-
$this->sql = array_merge($this->sql, $sql);
57-
} else {
58-
$this->sql[] = $sql;
59-
}
46+
$this->sql = array_merge($this->sql, $sql);
6047

6148
return $this;
6249
}
6350

6451
/**
65-
* @return string[]
52+
* @return array<int, string>
6653
*/
67-
public function getSql()
54+
public function getSql() : array
6855
{
6956
return $this->sql;
7057
}

0 commit comments

Comments
 (0)