Skip to content

Commit 7becd18

Browse files
committed
Merge pull request doctrine#3348 from morozov/types
Enforce parameter and return value types in the codebase
2 parents 85dbd61 + f5dd1cb commit 7becd18

22 files changed

+99
-185
lines changed

UPGRADE.md

Lines changed: 6 additions & 0 deletions
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\Schema` API
4+
5+
- Column precision no longer defaults to 10. The default value is NULL.
6+
- Asset names are no longer nullable. An empty asset name should be represented as an empty string.
7+
- `Doctrine\DBAL\Schema\AbstractSchemaManager::_getPortableTriggersList()` and `::_getPortableTriggerDefinition()` have been removed.
8+
39
## BC BREAK: Changes in the `Doctrine\DBAL\Event` API
410

511
- `SchemaAlterTableAddColumnEventArgs::addSql()` and the same method in other `SchemaEventArgs`-based classes no longer accept an array of SQL statements. They accept a variadic string.

lib/Doctrine/DBAL/Schema/AbstractAsset.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
abstract class AbstractAsset
2626
{
2727
/** @var string */
28-
protected $_name;
28+
protected $_name = '';
2929

3030
/**
3131
* Namespace of the asset. If none isset the default namespace is assumed.
@@ -138,7 +138,7 @@ public function getName() : string
138138
return $this->_namespace . '.' . $this->_name;
139139
}
140140

141-
return $this->_name ?? '';
141+
return $this->_name;
142142
}
143143

144144
/**
@@ -167,7 +167,7 @@ public function getQuotedName(AbstractPlatform $platform) : string
167167
*/
168168
protected function _generateIdentifierName(array $columnNames, string $prefix = '', int $maxSize = 30) : string
169169
{
170-
$hash = implode('', array_map(static function ($column) {
170+
$hash = implode('', array_map(static function ($column) : string {
171171
return dechex(crc32($column));
172172
}, $columnNames));
173173

lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public function listTableNames() : array
223223
*
224224
* @return array<int, mixed>
225225
*/
226-
protected function filterAssetNames(array $assetNames)
226+
protected function filterAssetNames(array $assetNames) : array
227227
{
228228
$filter = $this->_conn->getConfiguration()->getSchemaAssetsFilter();
229229
if (! $filter) {
@@ -605,35 +605,6 @@ protected function getPortableNamespaceDefinition(array $namespace) : string
605605
return array_shift($namespace);
606606
}
607607

608-
/**
609-
* @param array<int, array<int, mixed>> $triggers
610-
*
611-
* @return array<int, string>
612-
*/
613-
protected function _getPortableTriggersList(array $triggers)
614-
{
615-
$list = [];
616-
foreach ($triggers as $value) {
617-
$value = $this->_getPortableTriggerDefinition($value);
618-
619-
if (! $value) {
620-
continue;
621-
}
622-
623-
$list[] = $value;
624-
}
625-
626-
return $list;
627-
}
628-
629-
/**
630-
* @param array<string|int, mixed> $trigger
631-
*/
632-
protected function _getPortableTriggerDefinition(array $trigger) : string
633-
{
634-
return array_shift($trigger);
635-
}
636-
637608
/**
638609
* @param array<int, array<string, mixed>> $sequences
639610
*

lib/Doctrine/DBAL/Schema/Column.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Column extends AbstractAsset
2323
protected $_length;
2424

2525
/** @var int|null */
26-
protected $_precision = 10;
26+
protected $_precision;
2727

2828
/** @var int */
2929
protected $_scale = 0;
@@ -106,10 +106,6 @@ public function setLength(?int $length) : self
106106

107107
public function setPrecision(?int $precision) : self
108108
{
109-
if ($precision === null) {
110-
$precision = 10; // defaults to 10 when no precision is given.
111-
}
112-
113109
$this->_precision = $precision;
114110

115111
return $this;
@@ -195,7 +191,7 @@ public function getPrecision() : ?int
195191
return $this->_precision;
196192
}
197193

198-
public function getScale() : ?int
194+
public function getScale() : int
199195
{
200196
return $this->_scale;
201197
}

lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ class ForeignKeyConstraint extends AbstractAsset implements Constraint
5959
* @param array<int, string> $localColumnNames Names of the referencing table columns.
6060
* @param Table|string $foreignTableName Referenced table.
6161
* @param array<int, string> $foreignColumnNames Names of the referenced table columns.
62-
* @param string|null $name Name of the foreign key constraint.
62+
* @param string $name Name of the foreign key constraint.
6363
* @param array<string, mixed> $options Options associated with the foreign key constraint.
6464
*/
65-
public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, $name = null, array $options = [])
65+
public function __construct(array $localColumnNames, $foreignTableName, array $foreignColumnNames, string $name = '', array $options = [])
6666
{
67-
if ($name !== null) {
68-
$this->_setName($name);
69-
}
67+
$this->_setName($name);
7068

7169
$this->_localColumnNames = $this->createIdentifierMap($localColumnNames);
7270

lib/Doctrine/DBAL/Schema/PostgreSqlSchemaManager.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function determineExistingSchemaSearchPaths() : void
9292
$names = $this->getSchemaNames();
9393
$paths = $this->getSchemaSearchPaths();
9494

95-
$this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) {
95+
$this->existingSchemaPaths = array_filter($paths, static function ($v) use ($names) : bool {
9696
return in_array($v, $names);
9797
});
9898
}
@@ -161,14 +161,6 @@ protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey)
161161
);
162162
}
163163

164-
/**
165-
* {@inheritdoc}
166-
*/
167-
protected function _getPortableTriggerDefinition(array $trigger) : string
168-
{
169-
return $trigger['trigger_name'];
170-
}
171-
172164
/**
173165
* {@inheritdoc}
174166
*/

lib/Doctrine/DBAL/Schema/SQLAnywhereSchemaManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ public function dropDatabase(string $database) : void
4545
parent::dropDatabase($database);
4646
}
4747

48-
public function startDatabase(string $database)
48+
public function startDatabase(string $database) : void
4949
{
5050
assert($this->_platform instanceof SQLAnywherePlatform);
5151
$this->_execSql($this->_platform->getStartDatabaseSQL($database));
5252
}
5353

54-
public function stopDatabase(string $database)
54+
public function stopDatabase(string $database) : void
5555
{
5656
assert($this->_platform instanceof SQLAnywherePlatform);
5757
$this->_execSql($this->_platform->getStopDatabaseSQL($database));

lib/Doctrine/DBAL/Schema/Schema.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ public function visit(Visitor $visitor) : void
408408

409409
/**
410410
* Cloning a Schema triggers a deep clone of all related assets.
411-
*
412-
* @return void
413411
*/
414412
public function __clone()
415413
{

lib/Doctrine/DBAL/Schema/SchemaDiff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected function _toSql(AbstractPlatform $platform, bool $saveMode = false) :
120120
}
121121
}
122122

123-
if ($platform->supportsSequences() === true) {
123+
if ($platform->supportsSequences()) {
124124
foreach ($this->changedSequences as $sequence) {
125125
$sql[] = $platform->getAlterSequenceSQL($sequence);
126126
}

lib/Doctrine/DBAL/Schema/Table.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ public function getColumns() : array
462462

463463
$colNames = array_unique(array_merge($pkCols, $fkCols, array_keys($columns)));
464464

465-
uksort($columns, static function ($a, $b) use ($colNames) {
465+
uksort($columns, static function ($a, $b) use ($colNames) : bool {
466466
return array_search($a, $colNames) >= array_search($b, $colNames);
467467
});
468468

@@ -580,7 +580,7 @@ public function getUniqueConstraints() : array
580580
*
581581
* @return array<string, ForeignKeyConstraint>
582582
*/
583-
public function getForeignKeys()
583+
public function getForeignKeys() : array
584584
{
585585
return $this->_fkConstraints;
586586
}
@@ -625,8 +625,6 @@ public function visit(Visitor $visitor) : void
625625

626626
/**
627627
* Clone of a Table triggers a deep clone of all affected assets.
628-
*
629-
* @return void
630628
*/
631629
public function __clone()
632630
{

0 commit comments

Comments
 (0)