Skip to content

Commit d0154ea

Browse files
authored
Merge pull request #6610 from morozov/deprecate-set-name
Deprecate AbstractAsset::_setName()
2 parents 5d6640a + b2695ae commit d0154ea

12 files changed

+56
-18
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ awareness about deprecated code.
88

99
# Upgrade to 4.3
1010

11+
## Deprecated `AbstractAsset::_setName()`
12+
13+
Setting object name via `AbstractAsset::_setName()` has been deprecated. Pass the name to the `AbstractAsset`
14+
constructor instead.
15+
1116
## Marked `Identifier` class as internal
1217

1318
In order to build SQL identifiers, use `AbstractPlatform::quoteSingleIdentifier()`.

psalm.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@
102102
-->
103103
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::createReservedKeywordsList" />
104104
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getReservedKeywordsList" />
105+
106+
<!--
107+
https://github.com/doctrine/dbal/pull/6610
108+
TODO: remove in 5.0.0
109+
-->
110+
<referencedMethod name="Doctrine\DBAL\Schema\AbstractAsset::_setName" />
105111
</errorLevel>
106112
</DeprecatedMethod>
107113
<DeprecatedProperty>

src/Schema/AbstractAsset.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,36 @@ abstract class AbstractAsset
4545

4646
private bool $validateFuture = false;
4747

48+
public function __construct(?string $name = null)
49+
{
50+
if ($name === null) {
51+
Deprecation::trigger(
52+
'doctrine/dbal',
53+
'https://github.com/doctrine/dbal/pull/6610',
54+
'Not passing $name to %s is deprecated.',
55+
__METHOD__,
56+
);
57+
58+
return;
59+
}
60+
61+
$this->_setName($name);
62+
}
63+
4864
/**
4965
* Sets the name of this asset.
66+
*
67+
* @deprecated Use the constructor instead.
5068
*/
5169
protected function _setName(string $name): void
5270
{
71+
Deprecation::triggerIfCalledFromOutside(
72+
'doctrine/dbal',
73+
'https://github.com/doctrine/dbal/pull/6610',
74+
'%s is deprecated. Use the constructor instead.',
75+
__METHOD__,
76+
);
77+
5378
$input = $name;
5479

5580
if ($this->isIdentifierQuoted($name)) {

src/Schema/Column.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class Column extends AbstractAsset
5050
*/
5151
public function __construct(string $name, Type $type, array $options = [])
5252
{
53-
$this->_setName($name);
53+
parent::__construct($name);
54+
5455
$this->setType($type);
5556
$this->setOptions($options);
5657
}

src/Schema/ForeignKeyConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(
5353
string $name = '',
5454
protected array $options = [],
5555
) {
56-
$this->_setName($name);
56+
parent::__construct($name);
5757

5858
$this->_localColumnNames = $this->createIdentifierMap($localColumnNames);
5959
$this->_foreignTableName = new Identifier($foreignTableName);

src/Schema/Identifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Identifier extends AbstractAsset
2020
*/
2121
public function __construct(string $identifier, bool $quote = false)
2222
{
23-
$this->_setName($identifier);
23+
parent::__construct($identifier);
2424

2525
if (! $quote || $this->_quoted) {
2626
return;

src/Schema/Index.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,9 @@ public function __construct(
4747
array $flags = [],
4848
private readonly array $options = [],
4949
) {
50-
$isUnique = $isUnique || $isPrimary;
50+
parent::__construct($name ?? '');
5151

52-
if ($name !== null) {
53-
$this->_setName($name);
54-
}
55-
56-
$this->_isUnique = $isUnique;
52+
$this->_isUnique = $isUnique || $isPrimary;
5753
$this->_isPrimary = $isPrimary;
5854

5955
foreach ($columns as $column) {

src/Schema/Schema.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ public function __construct(
7676

7777
$name = $schemaConfig->getName();
7878

79-
if ($name !== null) {
80-
$this->_setName($name);
81-
}
79+
parent::__construct($name ?? '');
8280

8381
foreach ($namespaces as $namespace) {
8482
$this->createNamespace($namespace);
@@ -290,7 +288,12 @@ public function createTable(string $name): Table
290288
public function renameTable(string $oldName, string $newName): self
291289
{
292290
$table = $this->getTable($oldName);
293-
$table->_setName($newName);
291+
292+
$identifier = new Identifier($newName);
293+
294+
$table->_name = $identifier->_name;
295+
$table->_namespace = $identifier->_namespace;
296+
$table->_quoted = $identifier->_quoted;
294297

295298
$this->dropTable($oldName);
296299
$this->_addTable($table);

src/Schema/Sequence.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public function __construct(
2222
int $initialValue = 1,
2323
protected ?int $cache = null,
2424
) {
25-
$this->_setName($name);
25+
parent::__construct($name);
26+
2627
$this->setAllocationSize($allocationSize);
2728
$this->setInitialValue($initialValue);
2829
}

src/Schema/Table.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __construct(
8282
throw InvalidTableName::new($name);
8383
}
8484

85-
$this->_setName($name);
85+
parent::__construct($name);
8686

8787
foreach ($columns as $column) {
8888
$this->_addColumn($column);
@@ -299,7 +299,8 @@ final public function renameColumn(string $oldName, string $newName): Column
299299
}
300300

301301
$column = $this->getColumn($oldName);
302-
$column->_setName($newName);
302+
303+
$column->_name = $newName;
303304
unset($this->_columns[$oldName]);
304305
$this->_addColumn($column);
305306

0 commit comments

Comments
 (0)