From 6d2b0212be011e900110da1171e58bc6f357b985 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 7 Oct 2022 13:09:42 -0700 Subject: [PATCH 1/2] Remove irrelevant @throws annotations --- src/Schema/Schema.php | 2 -- src/Schema/Table.php | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index 10b4d7babf4..03aeb74acb2 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -366,8 +366,6 @@ public function toSql(AbstractPlatform $platform): array * Return an array of necessary SQL queries to drop the schema on the given platform. * * @return list - * - * @throws Exception */ public function toDropSql(AbstractPlatform $platform): array { diff --git a/src/Schema/Table.php b/src/Schema/Table.php index ee91a6e0a37..08a5b1d30eb 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -4,7 +4,6 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Exception\ColumnAlreadyExists; use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Doctrine\DBAL\Schema\Exception\ForeignKeyDoesNotExist; @@ -59,7 +58,6 @@ class Table extends AbstractAsset * @param array $options * * @throws SchemaException - * @throws Exception */ public function __construct( string $name, From bb16de1c6b020e56bcd46e46d0045d3834c4672a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 7 Oct 2022 13:08:32 -0700 Subject: [PATCH 2/2] Convert Doctrine\DBAL\Schema\SchemaException to an interface --- UPGRADE.md | 4 +- src/Schema/Column.php | 8 +--- src/Schema/Comparator.php | 2 - src/Schema/Exception/ColumnAlreadyExists.php | 3 +- src/Schema/Exception/ColumnDoesNotExist.php | 3 +- .../Exception/ForeignKeyDoesNotExist.php | 3 +- src/Schema/Exception/IndexAlreadyExists.php | 3 +- src/Schema/Exception/IndexDoesNotExist.php | 3 +- src/Schema/Exception/IndexNameInvalid.php | 3 +- src/Schema/Exception/InvalidTableName.php | 3 +- .../Exception/NamespaceAlreadyExists.php | 3 +- .../Exception/SequenceAlreadyExists.php | 3 +- src/Schema/Exception/SequenceDoesNotExist.php | 3 +- src/Schema/Exception/TableAlreadyExists.php | 3 +- src/Schema/Exception/TableDoesNotExist.php | 3 +- .../UniqueConstraintDoesNotExist.php | 3 +- src/Schema/Exception/UnknownColumnOption.php | 3 +- src/Schema/Schema.php | 16 ------- src/Schema/SchemaException.php | 2 +- src/Schema/Table.php | 48 ++----------------- 20 files changed, 35 insertions(+), 87 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index ee4df29ee21..5a8fa49ef6d 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -33,9 +33,9 @@ The following `SchemaException` class constants have been removed: - `CONSTRAINT_DOESNT_EXIST`, - `NAMESPACE_ALREADY_EXISTS`. -## BC BREAK: The base exception class has been converted to an interface +## BC BREAK: Exception classes have been converted to interfaces -The Doctrine\DBAL\Exception class is now an interface. +The `Doctrine\DBAL\Exception` and the `Doctrine\DBAL\Schema\SchemaException` classes are now interfaces. ## BC BREAK: removed misspelled isFullfilledBy() method diff --git a/src/Schema/Column.php b/src/Schema/Column.php index d48eefc249c..8963cd7acb2 100644 --- a/src/Schema/Column.php +++ b/src/Schema/Column.php @@ -44,8 +44,6 @@ class Column extends AbstractAsset * Creates a new Column. * * @param array $options - * - * @throws SchemaException */ public function __construct(string $name, Type $type, array $options = []) { @@ -54,11 +52,7 @@ public function __construct(string $name, Type $type, array $options = []) $this->setOptions($options); } - /** - * @param array $options - * - * @throws SchemaException - */ + /** @param array $options */ public function setOptions(array $options): self { foreach ($options as $name => $value) { diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index 8b72faec5c6..7d5f7b3082f 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -24,8 +24,6 @@ public function __construct(private readonly AbstractPlatform $platform) /** * Returns a SchemaDiff object containing the differences between the schemas $fromSchema and $toSchema. - * - * @throws SchemaException */ public function compareSchemas(Schema $fromSchema, Schema $toSchema): SchemaDiff { diff --git a/src/Schema/Exception/ColumnAlreadyExists.php b/src/Schema/Exception/ColumnAlreadyExists.php index dd499880a67..53daac90706 100644 --- a/src/Schema/Exception/ColumnAlreadyExists.php +++ b/src/Schema/Exception/ColumnAlreadyExists.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class ColumnAlreadyExists extends SchemaException +final class ColumnAlreadyExists extends LogicException implements SchemaException { public static function new(string $tableName, string $columnName): self { diff --git a/src/Schema/Exception/ColumnDoesNotExist.php b/src/Schema/Exception/ColumnDoesNotExist.php index bcc99d06350..cb1cedf625b 100644 --- a/src/Schema/Exception/ColumnDoesNotExist.php +++ b/src/Schema/Exception/ColumnDoesNotExist.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class ColumnDoesNotExist extends SchemaException +final class ColumnDoesNotExist extends LogicException implements SchemaException { public static function new(string $columnName, string $table): self { diff --git a/src/Schema/Exception/ForeignKeyDoesNotExist.php b/src/Schema/Exception/ForeignKeyDoesNotExist.php index b9afb2d7d4c..3e4c6c6e4f0 100644 --- a/src/Schema/Exception/ForeignKeyDoesNotExist.php +++ b/src/Schema/Exception/ForeignKeyDoesNotExist.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class ForeignKeyDoesNotExist extends SchemaException +final class ForeignKeyDoesNotExist extends LogicException implements SchemaException { public static function new(string $foreignKeyName, string $table): self { diff --git a/src/Schema/Exception/IndexAlreadyExists.php b/src/Schema/Exception/IndexAlreadyExists.php index 66cc483df2f..e8592bee07a 100644 --- a/src/Schema/Exception/IndexAlreadyExists.php +++ b/src/Schema/Exception/IndexAlreadyExists.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class IndexAlreadyExists extends SchemaException +final class IndexAlreadyExists extends LogicException implements SchemaException { public static function new(string $indexName, string $table): self { diff --git a/src/Schema/Exception/IndexDoesNotExist.php b/src/Schema/Exception/IndexDoesNotExist.php index 38a6103406e..ee25fd852da 100644 --- a/src/Schema/Exception/IndexDoesNotExist.php +++ b/src/Schema/Exception/IndexDoesNotExist.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class IndexDoesNotExist extends SchemaException +final class IndexDoesNotExist extends LogicException implements SchemaException { public static function new(string $indexName, string $table): self { diff --git a/src/Schema/Exception/IndexNameInvalid.php b/src/Schema/Exception/IndexNameInvalid.php index 70036c83db5..d295eb8a276 100644 --- a/src/Schema/Exception/IndexNameInvalid.php +++ b/src/Schema/Exception/IndexNameInvalid.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use InvalidArgumentException; use function sprintf; /** @psalm-immutable */ -final class IndexNameInvalid extends SchemaException +final class IndexNameInvalid extends InvalidArgumentException implements SchemaException { public static function new(string $indexName): self { diff --git a/src/Schema/Exception/InvalidTableName.php b/src/Schema/Exception/InvalidTableName.php index 50e2d3af9b9..3b5d89dc135 100644 --- a/src/Schema/Exception/InvalidTableName.php +++ b/src/Schema/Exception/InvalidTableName.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use InvalidArgumentException; use function sprintf; /** @psalm-immutable */ -final class InvalidTableName extends SchemaException +final class InvalidTableName extends InvalidArgumentException implements SchemaException { public static function new(string $tableName): self { diff --git a/src/Schema/Exception/NamespaceAlreadyExists.php b/src/Schema/Exception/NamespaceAlreadyExists.php index dc3eef6df6c..4109af50881 100644 --- a/src/Schema/Exception/NamespaceAlreadyExists.php +++ b/src/Schema/Exception/NamespaceAlreadyExists.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class NamespaceAlreadyExists extends SchemaException +final class NamespaceAlreadyExists extends LogicException implements SchemaException { public static function new(string $namespaceName): self { diff --git a/src/Schema/Exception/SequenceAlreadyExists.php b/src/Schema/Exception/SequenceAlreadyExists.php index 62d741f7a9d..d374f27379a 100644 --- a/src/Schema/Exception/SequenceAlreadyExists.php +++ b/src/Schema/Exception/SequenceAlreadyExists.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class SequenceAlreadyExists extends SchemaException +final class SequenceAlreadyExists extends LogicException implements SchemaException { public static function new(string $sequenceName): self { diff --git a/src/Schema/Exception/SequenceDoesNotExist.php b/src/Schema/Exception/SequenceDoesNotExist.php index 910cc59aa7f..fa98cee02ff 100644 --- a/src/Schema/Exception/SequenceDoesNotExist.php +++ b/src/Schema/Exception/SequenceDoesNotExist.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class SequenceDoesNotExist extends SchemaException +final class SequenceDoesNotExist extends LogicException implements SchemaException { public static function new(string $sequenceName): self { diff --git a/src/Schema/Exception/TableAlreadyExists.php b/src/Schema/Exception/TableAlreadyExists.php index 8b7ea083690..b978dbc6ebc 100644 --- a/src/Schema/Exception/TableAlreadyExists.php +++ b/src/Schema/Exception/TableAlreadyExists.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class TableAlreadyExists extends SchemaException +final class TableAlreadyExists extends LogicException implements SchemaException { public static function new(string $tableName): self { diff --git a/src/Schema/Exception/TableDoesNotExist.php b/src/Schema/Exception/TableDoesNotExist.php index 0f7f76c45ac..8c66a11a477 100644 --- a/src/Schema/Exception/TableDoesNotExist.php +++ b/src/Schema/Exception/TableDoesNotExist.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class TableDoesNotExist extends SchemaException +final class TableDoesNotExist extends LogicException implements SchemaException { public static function new(string $tableName): self { diff --git a/src/Schema/Exception/UniqueConstraintDoesNotExist.php b/src/Schema/Exception/UniqueConstraintDoesNotExist.php index c3bb304dcdc..3ae5aaa27ab 100644 --- a/src/Schema/Exception/UniqueConstraintDoesNotExist.php +++ b/src/Schema/Exception/UniqueConstraintDoesNotExist.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use LogicException; use function sprintf; /** @psalm-immutable */ -final class UniqueConstraintDoesNotExist extends SchemaException +final class UniqueConstraintDoesNotExist extends LogicException implements SchemaException { public static function new(string $constraintName, string $table): self { diff --git a/src/Schema/Exception/UnknownColumnOption.php b/src/Schema/Exception/UnknownColumnOption.php index 7a7c6f87a17..a97ee76e565 100644 --- a/src/Schema/Exception/UnknownColumnOption.php +++ b/src/Schema/Exception/UnknownColumnOption.php @@ -5,11 +5,12 @@ namespace Doctrine\DBAL\Schema\Exception; use Doctrine\DBAL\Schema\SchemaException; +use InvalidArgumentException; use function sprintf; /** @psalm-immutable */ -final class UnknownColumnOption extends SchemaException +final class UnknownColumnOption extends InvalidArgumentException implements SchemaException { public static function new(string $name): self { diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index 03aeb74acb2..25fe4a3c6d8 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -63,8 +63,6 @@ class Schema extends AbstractAsset * @param array $tables * @param array $sequences * @param array $namespaces - * - * @throws SchemaException */ public function __construct( array $tables = [], @@ -95,7 +93,6 @@ public function __construct( } } - /** @throws SchemaException */ protected function _addTable(Table $table): void { $namespaceName = $table->getNamespaceName(); @@ -117,7 +114,6 @@ protected function _addTable(Table $table): void $table->setSchemaConfig($this->_schemaConfig); } - /** @throws SchemaException */ protected function _addSequence(Sequence $sequence): void { $namespaceName = $sequence->getNamespaceName(); @@ -158,7 +154,6 @@ public function getTables(): array return array_values($this->_tables); } - /** @throws SchemaException */ public function getTable(string $name): Table { $name = $this->getFullQualifiedAssetName($name); @@ -238,7 +233,6 @@ public function hasSequence(string $name): bool return isset($this->_sequences[$name]); } - /** @throws SchemaException */ public function getSequence(string $name): Sequence { $name = $this->getFullQualifiedAssetName($name); @@ -259,8 +253,6 @@ public function getSequences(): array * Creates a new namespace. * * @return $this - * - * @throws SchemaException */ public function createNamespace(string $name): self { @@ -277,8 +269,6 @@ public function createNamespace(string $name): self /** * Creates a new table. - * - * @throws SchemaException */ public function createTable(string $name): Table { @@ -296,8 +286,6 @@ public function createTable(string $name): Table * Renames a table. * * @return $this - * - * @throws SchemaException */ public function renameTable(string $oldName, string $newName): self { @@ -314,8 +302,6 @@ public function renameTable(string $oldName, string $newName): self * Drops a table from the schema. * * @return $this - * - * @throws SchemaException */ public function dropTable(string $name): self { @@ -328,8 +314,6 @@ public function dropTable(string $name): self /** * Creates a new sequence. - * - * @throws SchemaException */ public function createSequence(string $name, int $allocationSize = 1, int $initialValue = 1): Sequence { diff --git a/src/Schema/SchemaException.php b/src/Schema/SchemaException.php index d7b86f83e9e..43dd2ad862c 100644 --- a/src/Schema/SchemaException.php +++ b/src/Schema/SchemaException.php @@ -7,6 +7,6 @@ use Doctrine\DBAL\Exception; /** @psalm-immutable */ -class SchemaException extends \Exception implements Exception +interface SchemaException extends Exception { } diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 08a5b1d30eb..9abc027b57f 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -56,8 +56,6 @@ class Table extends AbstractAsset * @param array $uniqueConstraints * @param array $fkConstraints * @param array $options - * - * @throws SchemaException */ public function __construct( string $name, @@ -101,8 +99,6 @@ public function setSchemaConfig(SchemaConfig $schemaConfig): void * Sets the Primary Key. * * @param array $columnNames - * - * @throws SchemaException */ public function setPrimaryKey(array $columnNames, ?string $indexName = null): self { @@ -124,8 +120,6 @@ public function setPrimaryKey(array $columnNames, ?string $indexName = null): se * @param array $columnNames * @param array $flags * @param array $options - * - * @throws SchemaException */ public function addUniqueConstraint( array $columnNames, @@ -164,8 +158,6 @@ public function addIndex( /** * Drops the primary key from this table. - * - * @throws SchemaException */ public function dropPrimaryKey(): void { @@ -179,8 +171,6 @@ public function dropPrimaryKey(): void /** * Drops an index from this table. - * - * @throws SchemaException If the index does not exist. */ public function dropIndex(string $name): void { @@ -196,8 +186,6 @@ public function dropIndex(string $name): void /** * @param array $columnNames * @param array $options - * - * @throws SchemaException */ public function addUniqueIndex(array $columnNames, ?string $indexName = null, array $options = []): self { @@ -214,11 +202,8 @@ public function addUniqueIndex(array $columnNames, ?string $indexName = null, ar * Renames an index. * * @param string $oldName The name of the index to rename from. - * @param string|null $newName The name of the index to rename to. - * If null is given, the index name will be auto-generated. - * - * @throws SchemaException If no index exists for the given current name - * or if an index with the given new name already exists on this table. + * @param string|null $newName The name of the index to rename to. If null is given, the index name + * will be auto-generated. */ public function renameIndex(string $oldName, ?string $newName = null): self { @@ -270,11 +255,7 @@ public function columnsAreIndexed(array $columnNames): bool return false; } - /** - * @param array $options - * - * @throws SchemaException - */ + /** @param array $options */ public function addColumn(string $name, string $typeName, array $options = []): Column { $column = new Column($name, Type::getType($typeName), $options); @@ -288,8 +269,6 @@ public function addColumn(string $name, string $typeName, array $options = []): * Change Column Details. * * @param array $options - * - * @throws SchemaException */ public function changeColumn(string $name, array $options): self { @@ -319,8 +298,6 @@ public function dropColumn(string $name): self * @param array $localColumnNames * @param array $foreignColumnNames * @param array $options - * - * @throws SchemaException */ public function addForeignKeyConstraint( string $foreignTableName, @@ -371,8 +348,6 @@ public function hasForeignKey(string $name): bool /** * Returns the foreign key constraint with the given name. - * - * @throws SchemaException If the foreign key does not exist. */ public function getForeignKey(string $name): ForeignKeyConstraint { @@ -387,8 +362,6 @@ public function getForeignKey(string $name): ForeignKeyConstraint /** * Removes the foreign key constraint with the given name. - * - * @throws SchemaException */ public function removeForeignKey(string $name): void { @@ -413,8 +386,6 @@ public function hasUniqueConstraint(string $name): bool /** * Returns the unique constraint with the given name. - * - * @throws SchemaException If the unique constraint does not exist. */ public function getUniqueConstraint(string $name): UniqueConstraint { @@ -429,8 +400,6 @@ public function getUniqueConstraint(string $name): UniqueConstraint /** * Removes the unique constraint with the given name. - * - * @throws SchemaException If the unique constraint does not exist. */ public function removeUniqueConstraint(string $name): void { @@ -465,8 +434,6 @@ public function hasColumn(string $name): bool /** * Returns the Column with the given name. - * - * @throws SchemaException If the column does not exist. */ public function getColumn(string $name): Column { @@ -503,8 +470,6 @@ public function hasIndex(string $name): bool /** * Returns the Index with the given name. - * - * @throws SchemaException If the index does not exist. */ public function getIndex(string $name): Index { @@ -584,7 +549,6 @@ protected function _getMaxIdentifierLength(): int : 63; } - /** @throws SchemaException */ protected function _addColumn(Column $column): void { $columnName = $column->getName(); @@ -599,8 +563,6 @@ protected function _addColumn(Column $column): void /** * Adds an index to the table. - * - * @throws SchemaException */ protected function _addIndex(Index $indexCandidate): self { @@ -741,8 +703,6 @@ public function getComment(): ?string * @param array $columns * @param array $flags * @param array $options - * - * @throws SchemaException */ private function _createUniqueConstraint( array $columns, @@ -773,8 +733,6 @@ private function _createUniqueConstraint( * @param array $columns * @param array $flags * @param array $options - * - * @throws SchemaException */ private function _createIndex( array $columns,