Skip to content

Commit

Permalink
Merge pull request doctrine#5735 from morozov/schema-exception-interface
Browse files Browse the repository at this point in the history
Convert Doctrine\DBAL\Schema\SchemaException to an interface
  • Loading branch information
morozov committed Oct 9, 2022
2 parents 7e284a6 + bb16de1 commit a8a2650
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 91 deletions.
4 changes: 2 additions & 2 deletions UPGRADE.md
Expand Up @@ -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

Expand Down
8 changes: 1 addition & 7 deletions src/Schema/Column.php
Expand Up @@ -44,8 +44,6 @@ class Column extends AbstractAsset
* Creates a new Column.
*
* @param array<string, mixed> $options
*
* @throws SchemaException
*/
public function __construct(string $name, Type $type, array $options = [])
{
Expand All @@ -54,11 +52,7 @@ public function __construct(string $name, Type $type, array $options = [])
$this->setOptions($options);
}

/**
* @param array<string, mixed> $options
*
* @throws SchemaException
*/
/** @param array<string, mixed> $options */
public function setOptions(array $options): self
{
foreach ($options as $name => $value) {
Expand Down
2 changes: 0 additions & 2 deletions src/Schema/Comparator.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/ColumnAlreadyExists.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/ColumnDoesNotExist.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/ForeignKeyDoesNotExist.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/IndexAlreadyExists.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/IndexDoesNotExist.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/IndexNameInvalid.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/InvalidTableName.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/NamespaceAlreadyExists.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/SequenceAlreadyExists.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/SequenceDoesNotExist.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/TableAlreadyExists.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/TableDoesNotExist.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/UniqueConstraintDoesNotExist.php
Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Exception/UnknownColumnOption.php
Expand Up @@ -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
{
Expand Down
18 changes: 0 additions & 18 deletions src/Schema/Schema.php
Expand Up @@ -63,8 +63,6 @@ class Schema extends AbstractAsset
* @param array<Table> $tables
* @param array<Sequence> $sequences
* @param array<string> $namespaces
*
* @throws SchemaException
*/
public function __construct(
array $tables = [],
Expand Down Expand Up @@ -95,7 +93,6 @@ public function __construct(
}
}

/** @throws SchemaException */
protected function _addTable(Table $table): void
{
$namespaceName = $table->getNamespaceName();
Expand All @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -259,8 +253,6 @@ public function getSequences(): array
* Creates a new namespace.
*
* @return $this
*
* @throws SchemaException
*/
public function createNamespace(string $name): self
{
Expand All @@ -277,8 +269,6 @@ public function createNamespace(string $name): self

/**
* Creates a new table.
*
* @throws SchemaException
*/
public function createTable(string $name): Table
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand All @@ -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
{
Expand Down Expand Up @@ -366,8 +350,6 @@ public function toSql(AbstractPlatform $platform): array
* Return an array of necessary SQL queries to drop the schema on the given platform.
*
* @return list<string>
*
* @throws Exception
*/
public function toDropSql(AbstractPlatform $platform): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/SchemaException.php
Expand Up @@ -7,6 +7,6 @@
use Doctrine\DBAL\Exception;

/** @psalm-immutable */
class SchemaException extends \Exception implements Exception
interface SchemaException extends Exception
{
}

0 comments on commit a8a2650

Please sign in to comment.