From c66a2823e77043fde6be157284ba2e0e7857e200 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 8 Oct 2022 09:07:41 -0700 Subject: [PATCH 1/2] Remove obsolete Psalm error suppressions --- psalm.xml.dist | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/psalm.xml.dist b/psalm.xml.dist index ae436b317bd..38c136d872a 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -42,23 +42,11 @@ - - - - - - - - - - - - diff --git a/src/Schema/Table.php b/src/Schema/Table.php index d7d2866905d..ee91a6e0a37 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -14,19 +14,14 @@ use Doctrine\DBAL\Schema\Exception\InvalidTableName; use Doctrine\DBAL\Schema\Exception\UniqueConstraintDoesNotExist; use Doctrine\DBAL\Types\Type; -use Doctrine\Deprecations\Deprecation; -use function array_filter; use function array_merge; use function array_values; use function in_array; use function is_string; use function preg_match; -use function sprintf; use function strtolower; -use const ARRAY_FILTER_USE_KEY; - /** * Object Representation of a table. */ @@ -460,20 +455,6 @@ public function getColumns(): array return array_values($this->_columns); } - /** - * Returns only columns that have specified names - * - * @param string[] $columnNames - * - * @return Column[] - */ - private function filterColumns(array $columnNames, bool $reverse = false): array - { - return array_filter($this->_columns, static function (string $columnName) use ($columnNames, $reverse): bool { - return in_array($columnName, $columnNames, true) !== $reverse; - }, ARRAY_FILTER_USE_KEY); - } - /** * Returns whether this table has a Column with the given name. */ @@ -512,50 +493,6 @@ public function getPrimaryKey(): ?Index return null; } - /** - * Returns the primary key columns. - * - * @deprecated Use {@see getPrimaryKey()} and {@see Index::getColumns()} instead. - * - * @return array - * - * @throws SchemaException - */ - public function getPrimaryKeyColumns(): array - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/5731', - '%s is deprecated. Use getPrimaryKey() and Index::getColumns() instead.', - __METHOD__, - ); - - $primaryKey = $this->getPrimaryKey(); - - if ($primaryKey === null) { - throw new SchemaException(sprintf('Table "%s" has no primary key.', $this->getName())); - } - - return $this->filterColumns($primaryKey->getColumns()); - } - - /** - * Returns whether this table has a primary key. - * - * @deprecated Use {@see getPrimaryKey()} instead. - */ - public function hasPrimaryKey(): bool - { - Deprecation::trigger( - 'doctrine/dbal', - 'https://github.com/doctrine/dbal/pull/5731', - '%s is deprecated. Use getPrimaryKey() instead.', - __METHOD__, - ); - - return $this->_primaryKeyName !== null && $this->hasIndex($this->_primaryKeyName); - } - /** * Returns whether this table has an Index with the given name. */ diff --git a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php index a06fd678a81..5a830c62039 100644 --- a/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php +++ b/tests/Functional/Platform/NewPrimaryKeyWithNewAutoIncrementColumnTest.php @@ -56,9 +56,10 @@ public function testAlterPrimaryKeyToAutoIncrementColumn(): void self::assertTrue($validationTable->hasColumn('new_id')); self::assertTrue($validationTable->getColumn('new_id')->getAutoincrement()); - self::assertTrue($validationTable->hasPrimaryKey()); - self::assertCount(1, $validationTable->getPrimaryKeyColumns()); - self::assertArrayHasKey('new_id', $validationTable->getPrimaryKeyColumns()); + + $primaryKey = $validationTable->getPrimaryKey(); + self::assertNotNull($primaryKey); + self::assertSame(['new_id'], $primaryKey->getColumns()); } private function getPlatform(): AbstractPlatform diff --git a/tests/Functional/Platform/PlatformRestrictionsTest.php b/tests/Functional/Platform/PlatformRestrictionsTest.php index 3a499908e7a..1423c97bf84 100644 --- a/tests/Functional/Platform/PlatformRestrictionsTest.php +++ b/tests/Functional/Platform/PlatformRestrictionsTest.php @@ -31,6 +31,6 @@ public function testMaxIdentifierLengthLimitWithAutoIncrement(): void $createdTable = $this->connection->createSchemaManager()->introspectTable($tableName); self::assertTrue($createdTable->hasColumn($columnName)); - self::assertTrue($createdTable->hasPrimaryKey()); + self::assertNotNull($createdTable->getPrimaryKey()); } } diff --git a/tests/Functional/Schema/MySQLSchemaManagerTest.php b/tests/Functional/Schema/MySQLSchemaManagerTest.php index 3c533c6601d..dc0cc1eb87a 100644 --- a/tests/Functional/Schema/MySQLSchemaManagerTest.php +++ b/tests/Functional/Schema/MySQLSchemaManagerTest.php @@ -45,12 +45,11 @@ public function testSwitchPrimaryKeyColumns(): void $this->schemaManager->alterTable($diff); - $table = $this->schemaManager->introspectTable('switch_primary_key_columns'); - $primaryKey = $table->getPrimaryKeyColumns(); + $table = $this->schemaManager->introspectTable('switch_primary_key_columns'); - self::assertCount(2, $primaryKey); - self::assertArrayHasKey('bar_id', $primaryKey); - self::assertArrayHasKey('foo_id', $primaryKey); + $primaryKey = $table->getPrimaryKey(); + self::assertNotNull($primaryKey); + self::assertSame(['bar_id', 'foo_id'], $primaryKey->getColumns()); } public function testFulltextIndex(): void @@ -127,7 +126,7 @@ public function testAlterTableAddPrimaryKey(): void $table = $this->schemaManager->introspectTable('alter_table_add_pk'); self::assertFalse($table->hasIndex('idx_id')); - self::assertTrue($table->hasPrimaryKey()); + self::assertNotNull($table->getPrimaryKey()); } public function testDropPrimaryKeyWithAutoincrementColumn(): void @@ -151,7 +150,7 @@ public function testDropPrimaryKeyWithAutoincrementColumn(): void $table = $this->schemaManager->introspectTable('drop_primary_key'); - self::assertFalse($table->hasPrimaryKey()); + self::assertNull($table->getPrimaryKey()); self::assertFalse($table->getColumn('id')->getAutoincrement()); } diff --git a/tests/Functional/Schema/OracleSchemaManagerTest.php b/tests/Functional/Schema/OracleSchemaManagerTest.php index 9170dcf1810..e1b733c21a3 100644 --- a/tests/Functional/Schema/OracleSchemaManagerTest.php +++ b/tests/Functional/Schema/OracleSchemaManagerTest.php @@ -119,7 +119,6 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() self::assertTrue($onlinePrimaryTable->hasColumn('"Id"')); self::assertSame('"Id"', $onlinePrimaryTable->getColumn('"Id"')->getQuotedName($platform)); - self::assertTrue($onlinePrimaryTable->hasPrimaryKey()); $onlinePrimaryTablePrimaryKey = $onlinePrimaryTable->getPrimaryKey(); self::assertNotNull($onlinePrimaryTablePrimaryKey); @@ -156,7 +155,6 @@ public function testListTableDetailsWithDifferentIdentifierQuotingRequirements() // Foreign table assertions self::assertTrue($onlineForeignTable->hasColumn('id')); self::assertSame('ID', $onlineForeignTable->getColumn('id')->getQuotedName($platform)); - self::assertTrue($onlineForeignTable->hasPrimaryKey()); $onlineForeignTablePrimaryKey = $onlineForeignTable->getPrimaryKey(); self::assertNotNull($onlineForeignTablePrimaryKey); diff --git a/tests/Schema/TableTest.php b/tests/Schema/TableTest.php index c5c0818fade..35f47d092e4 100644 --- a/tests/Schema/TableTest.php +++ b/tests/Schema/TableTest.php @@ -469,7 +469,7 @@ public function testPrimaryKeyOverrulingUniqueIndexDoesNotDropUniqueIndex(): voi // Table should only contain both the primary key table index and the unique one, even though it was overruled self::assertCount(2, $indexes); - self::assertTrue($table->hasPrimaryKey()); + self::assertNotNull($table->getPrimaryKey()); self::assertTrue($table->hasIndex('idx_unique')); } @@ -561,12 +561,12 @@ public function testTableHasPrimaryKey(): void { $table = new Table('test'); - self::assertFalse($table->hasPrimaryKey()); + self::assertNull($table->getPrimaryKey()); $table->addColumn('foo', 'integer'); $table->setPrimaryKey(['foo']); - self::assertTrue($table->hasPrimaryKey()); + self::assertNotNull($table->getPrimaryKey()); } public function testAddIndexWithQuotedColumns(): void @@ -614,10 +614,10 @@ public function testDropPrimaryKey(): void $table->addColumn('id', 'integer'); $table->setPrimaryKey(['id']); - self::assertTrue($table->hasPrimaryKey()); + self::assertNotNull($table->getPrimaryKey()); $table->dropPrimaryKey(); - self::assertFalse($table->hasPrimaryKey()); + self::assertNull($table->getPrimaryKey()); } public function testRenameIndex(): void @@ -636,7 +636,7 @@ public function testRenameIndex(): void self::assertSame($table, $table->renameIndex('idx', 'idx_new')); self::assertSame($table, $table->renameIndex('uniq', 'uniq_new')); - self::assertTrue($table->hasPrimaryKey()); + self::assertNotNull($table->getPrimaryKey()); self::assertTrue($table->hasIndex('pk_new')); self::assertTrue($table->hasIndex('idx_new')); self::assertTrue($table->hasIndex('uniq_new')); @@ -658,7 +658,7 @@ public function testRenameIndex(): void self::assertSame($table, $table->renameIndex('idx_new', null)); self::assertSame($table, $table->renameIndex('uniq_new', null)); - self::assertTrue($table->hasPrimaryKey()); + self::assertNotNull($table->getPrimaryKey()); self::assertTrue($table->hasIndex('primary')); self::assertTrue($table->hasIndex('IDX_D87F7E0C8C736521')); self::assertTrue($table->hasIndex('UNIQ_D87F7E0C76FF8CAA78240498')); @@ -683,7 +683,7 @@ public function testRenameIndex(): void self::assertSame($table, $table->renameIndex('IDX_D87F7E0C8C736521', 'idx_D87F7E0C8C736521')); self::assertSame($table, $table->renameIndex('UNIQ_D87F7E0C76FF8CAA78240498', 'uniq_D87F7E0C76FF8CAA78240498')); - self::assertTrue($table->hasPrimaryKey()); + self::assertNotNull($table->getPrimaryKey()); self::assertTrue($table->hasIndex('primary')); self::assertTrue($table->hasIndex('IDX_D87F7E0C8C736521')); self::assertTrue($table->hasIndex('UNIQ_D87F7E0C76FF8CAA78240498'));