Skip to content

Commit 456d8e0

Browse files
committed
Merge branch '4.4.x' into 5.0.x
2 parents a7a4e33 + af03149 commit 456d8e0

24 files changed

+302
-180
lines changed

UPGRADE.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,13 @@ all drivers and middleware.
356356

357357
# Upgrade to 4.4
358358

359+
## Deprecated `AbstractAsset::getName()`
360+
361+
The `AbstractAsset::getName()` method has been deprecated. Instead, use `NamedObject::getObjectName()` or
362+
`OptionallyQualifiedName::getObjectName()` to get the object representation of the name. SQL context, convert the
363+
resulting `Name` to SQL using `Name::toSQL()`. In other contexts, convert the resulting name to string using
364+
`Name::toString()`.
365+
359366
## Deprecated `AbstractAsset::isQuoted()`
360367

361368
The `AbstractAsset::isQuoted()` method has been deprecated. The recommended approach depends on the object class:
@@ -674,7 +681,7 @@ The `Table::__construct()` method has been marked as internal. Use `Table::edito
674681

675682
## Deprecated `AbstractAsset::getShortestName()`
676683

677-
The `AbstractAsset::getShortestName()` method has been deprecated. Use `AbstractAsset::getName()` instead.
684+
The `AbstractAsset::getShortestName()` method has been deprecated. Use `NamedObject::getObjectName()` instead.
678685

679686
## Deprecated `Sequence::isAutoIncrementsFor()`
680687

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
"psr/log": "^1|^2|^3"
3838
},
3939
"require-dev": {
40-
"doctrine/coding-standard": "13.0.0",
40+
"doctrine/coding-standard": "13.0.1",
4141
"fig/log-test": "^1",
4242
"jetbrains/phpstorm-stubs": "2023.2",
43-
"phpstan/phpstan": "2.1.17",
43+
"phpstan/phpstan": "2.1.22",
4444
"phpstan/phpstan-phpunit": "2.0.6",
4545
"phpstan/phpstan-strict-rules": "^2",
4646
"phpunit/phpunit": "12.3.0",

docs/en/reference/schema-manager.rst

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Now you can loop over the array inspecting each sequence object:
5959
6060
<?php
6161
foreach ($sequences as $sequence) {
62-
echo $sequence->getName() . "\n";
62+
echo $sequence->getObjectName()->toString() . PHP_EOL;
6363
}
6464
6565
listTableColumns()
@@ -79,7 +79,7 @@ Now you can loop over the array inspecting each column object:
7979
8080
<?php
8181
foreach ($columns as $column) {
82-
echo $column->getName() . ': ' . $column->getType() . "\n";
82+
echo $column->getObjectName()->toString() . ': ' . $column->getType() . PHP_EOL;
8383
}
8484
8585
introspectTable()
@@ -119,7 +119,7 @@ object:
119119
120120
<?php
121121
foreach ($foreignKeys as $foreignKey) {
122-
echo $foreignKey->getName() ."\n";
122+
echo $foreignKey->getObjectName()->toString() . PHP_EOL;
123123
}
124124
125125
listTableIndexes()
@@ -139,7 +139,12 @@ Now you can loop over the array inspecting each index object:
139139
140140
<?php
141141
foreach ($indexes as $index) {
142-
echo $index->getName() . ': ' . ($index->isUnique() ? 'unique' : 'not unique') . "\n";
142+
echo $index->getObjectName()->toString() . ': ' . match($index->getType()) {
143+
IndexType::REGULAR => 'regular',
144+
IndexType::UNIQUE => 'unique',
145+
IndexType::FULLTEXT => 'fulltext',
146+
IndexType::SPATIAL => 'spatial',
147+
} . PHP_EOL;
143148
}
144149
145150
listTables()
@@ -162,9 +167,9 @@ retrieved with the ``getColumns()`` method:
162167
163168
<?php
164169
foreach ($tables as $table) {
165-
echo $table->getName() . " columns:\n\n";
170+
echo $table->getObjectName()->toString() . " columns:" . PHP_EOL;
166171
foreach ($table->getColumns() as $column) {
167-
echo ' - ' . $column->getName() . "\n";
172+
echo ' - ' . $column->getObjectName()->toString() . PHP_EOL;
168173
}
169174
}
170175
@@ -185,7 +190,7 @@ Now you can loop over the array inspecting each view object:
185190
186191
<?php
187192
foreach ($views as $view) {
188-
echo $view->getName() . ': ' . $view->getSql() . "\n";
193+
echo $view->getObjectName()->toString() . ': ' . $view->getSql() . PHP_EOL;
189194
}
190195
191196
introspectSchema()

src/Schema/AbstractAsset.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ protected function trimQuotes(string $identifier): string
116116

117117
/**
118118
* Returns the name of this schema asset.
119+
*
120+
* @deprecated Use {@see NamedObject::getObjectName()} or {@see OptionallyQualifiedName::getObjectName()} instead.
121+
* In SQL context, convert the resulting {@see Name} to SQL using {@see Name::toSQL()}. In other
122+
* contexts, convert the resulting name to string using {@see Name::toString()}.
119123
*/
120124
public function getName(): string
121125
{

src/Schema/AbstractSchemaManager.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function listSchemaNames(): array
111111
/**
112112
* Lists the available sequences for this connection.
113113
*
114-
* @return array<int, Sequence>
114+
* @return list<Sequence>
115115
*
116116
* @throws Exception
117117
*/
@@ -209,7 +209,7 @@ public function tableExists(string $tableName): bool
209209
/**
210210
* Returns a list of all tables in the current database.
211211
*
212-
* @return array<int, non-empty-string>
212+
* @return list<non-empty-string>
213213
*
214214
* @throws Exception
215215
*/
@@ -218,6 +218,7 @@ public function listTableNames(): array
218218
$supportsSchemas = $this->platform->supportsSchemas();
219219
$currentSchemaName = $this->getCurrentSchemaName();
220220

221+
/** @phpstan-ignore return.type */
221222
return $this->filterAssetNames(
222223
array_map(static function (array $row) use ($supportsSchemas, $currentSchemaName): string {
223224
$name = $row[self::TABLE_NAME_COLUMN];
@@ -237,9 +238,11 @@ public function listTableNames(): array
237238
* Filters asset names if they are configured to return only a subset of all
238239
* the found elements.
239240
*
240-
* @param array<int, mixed> $assetNames
241+
* @param list<N> $assetNames
241242
*
242-
* @return array<int, mixed>
243+
* @return list<N>
244+
*
245+
* @template N
243246
*/
244247
private function filterAssetNames(array $assetNames): array
245248
{

src/Schema/Table.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ final public function renameColumn(string $oldName, string $newName): Column
302302
if ($oldName === $newName) {
303303
throw new LogicException(sprintf(
304304
'Attempt to rename column "%s.%s" to the same name.',
305-
$this->getName(),
305+
$this->name->toString(),
306306
$oldName,
307307
));
308308
}
@@ -609,10 +609,11 @@ public function dropUniqueConstraint(string $name): void
609609
/**
610610
* Returns the list of table columns.
611611
*
612-
* @return list<Column>
612+
* @return non-empty-list<Column>
613613
*/
614614
public function getColumns(): array
615615
{
616+
/** @phpstan-ignore return.type */
616617
return array_values($this->_columns);
617618
}
618619

tests/Functional/Driver/DBAL6024Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testDropPrimaryKey(): void
5454
$schemaManager->alterTable($diff);
5555

5656
$validationSchema = $schemaManager->introspectSchema();
57-
$validationTable = $validationSchema->getTable($table->getName());
57+
$validationTable = $validationSchema->getTable($table->getObjectName()->toString());
5858

5959
self::assertNull($validationTable->getPrimaryKeyConstraint());
6060
}

tests/Functional/Driver/DBAL6044Test.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ public function testUnloggedTables(): void
5353
$schemaManager = $this->connection->createSchemaManager();
5454

5555
$validationSchema = $schemaManager->introspectSchema();
56-
$validationUnloggedTable = $validationSchema->getTable($unloggedTable->getName());
56+
$validationUnloggedTable = $validationSchema->getTable($unloggedTable->getObjectName()->toString());
5757
self::assertTrue($validationUnloggedTable->getOption('unlogged'));
58-
$validationLoggedTable = $validationSchema->getTable($loggedTable->getName());
58+
$validationLoggedTable = $validationSchema->getTable($loggedTable->getObjectName()->toString());
5959
self::assertFalse($validationLoggedTable->getOption('unlogged'));
6060

6161
$sql = 'SELECT relpersistence FROM pg_class WHERE relname = ?';
6262
$stmt = $this->connection->prepare($sql);
6363

64-
$stmt->bindValue(1, $unloggedTable->getName());
64+
$stmt->bindValue(1, $unloggedTable->getObjectName()->toString());
6565
$unloggedTablePersistenceType = $stmt->executeQuery()->fetchOne();
6666
self::assertEquals('u', $unloggedTablePersistenceType);
6767

68-
$stmt->bindValue(1, $loggedTable->getName());
68+
$stmt->bindValue(1, $loggedTable->getObjectName()->toString());
6969
$loggedTablePersistenceType = $stmt->executeQuery()->fetchOne();
7070
self::assertEquals('p', $loggedTablePersistenceType);
7171
}

tests/Functional/Platform/AlterColumnTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
88
use Doctrine\DBAL\Schema\Column;
99
use Doctrine\DBAL\Schema\ColumnEditor;
10+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
1011
use Doctrine\DBAL\Schema\Table;
1112
use Doctrine\DBAL\Tests\FunctionalTestCase;
1213
use Doctrine\DBAL\Types\Types;
1314

15+
use function array_map;
16+
1417
class AlterColumnTest extends FunctionalTestCase
1518
{
1619
public function testColumnPositionRetainedAfterAltering(): void
@@ -45,12 +48,15 @@ public function testColumnPositionRetainedAfterAltering(): void
4548

4649
$sm->alterTable($diff);
4750

48-
$table = $sm->introspectTable('test_alter');
49-
$columns = $table->getColumns();
51+
$table = $sm->introspectTable('test_alter');
5052

51-
self::assertCount(2, $columns);
52-
self::assertEqualsIgnoringCase('c1', $columns[0]->getName());
53-
self::assertEqualsIgnoringCase('c2', $columns[1]->getName());
53+
$this->assertUnqualifiedNameListEquals([
54+
UnqualifiedName::unquoted('c1'),
55+
UnqualifiedName::unquoted('c2'),
56+
], array_map(
57+
static fn (Column $column): UnqualifiedName => $column->getObjectName(),
58+
$table->getColumns(),
59+
));
5460
}
5561

5662
public function testSupportsCollations(): void

tests/Functional/Platform/RenameColumnTest.php

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
namespace Doctrine\DBAL\Tests\Functional\Platform;
66

77
use Doctrine\DBAL\Schema\Column;
8+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
89
use Doctrine\DBAL\Schema\Table;
910
use Doctrine\DBAL\Schema\TableDiff;
1011
use Doctrine\DBAL\Tests\FunctionalTestCase;
1112
use Doctrine\DBAL\Types\Type;
1213
use Doctrine\DBAL\Types\Types;
1314
use PHPUnit\Framework\Attributes\DataProvider;
1415

16+
use function array_map;
17+
1518
class RenameColumnTest extends FunctionalTestCase
1619
{
1720
/**
@@ -55,12 +58,16 @@ public function testColumnPositionRetainedAfterImplicitRenaming(string $oldColum
5558

5659
$sm->alterTable($diff);
5760

58-
$table = $sm->introspectTable('test_rename');
59-
$columns = $table->getColumns();
61+
$table = $sm->introspectTable('test_rename');
62+
63+
$this->assertUnqualifiedNameListEquals([
64+
UnqualifiedName::unquoted($newColumnName),
65+
UnqualifiedName::unquoted('c2'),
66+
], array_map(
67+
static fn (Column $column): UnqualifiedName => $column->getObjectName(),
68+
$table->getColumns(),
69+
));
6070

61-
self::assertCount(2, $columns);
62-
self::assertEqualsIgnoringCase($newColumnName, $columns[0]->getName());
63-
self::assertEqualsIgnoringCase('c2', $columns[1]->getName());
6471
self::assertCount(1, self::getRenamedColumns($diff));
6572
self::assertCount(1, $diff->getRenamedColumns());
6673
}
@@ -74,7 +81,10 @@ public static function getRenamedColumns(TableDiff $tableDiff): array
7481
continue;
7582
}
7683

77-
$oldColumnName = $diff->getOldColumn()->getName();
84+
$oldColumnName = $diff->getOldColumn()
85+
->getObjectName()
86+
->toString();
87+
7888
$renamed[$oldColumnName] = $diff->getNewColumn();
7989
}
8090

@@ -116,22 +126,26 @@ public function testColumnPositionRetainedAfterExplicitRenaming(string $oldColum
116126

117127
$sm->alterTable($diff);
118128

119-
$table = $sm->introspectTable('test_rename');
120-
$columns = $table->getColumns();
129+
$table = $sm->introspectTable('test_rename');
121130

122131
self::assertCount(1, $diff->getChangedColumns());
123132
self::assertCount(1, $diff->getRenamedColumns());
124133
self::assertCount(1, $diff->getModifiedColumns());
125-
self::assertCount(2, $columns);
126-
self::assertEqualsIgnoringCase($newColumnName, $columns[0]->getName());
127-
self::assertEqualsIgnoringCase('c2', $columns[1]->getName());
134+
135+
$this->assertUnqualifiedNameListEquals([
136+
UnqualifiedName::unquoted($newColumnName),
137+
UnqualifiedName::unquoted('c2'),
138+
], array_map(
139+
static fn (Column $column): UnqualifiedName => $column->getObjectName(),
140+
$table->getColumns(),
141+
));
128142
}
129143

130144
/** @return iterable<array{non-empty-string,non-empty-string}> */
131145
public static function columnNameProvider(): iterable
132146
{
133147
yield ['c1', 'c1_x'];
134148
yield ['C1', 'c1_x'];
135-
yield ['importantColumn', 'veryImportantColumn'];
149+
yield ['importantColumn', 'very_important_column'];
136150
}
137151
}

0 commit comments

Comments
 (0)