Skip to content

Convert Doctrine\DBAL\Exception to an interface #5726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: The base exception class has been converted to an interface

The Doctrine\DBAL\Exception class is now an interface.

## BC BREAK: removed misspelled isFullfilledBy() method

This method's name was spelled incorrectly. Use `isFulfilledBy` instead.
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
use Doctrine\DBAL\Exception;

/** @psalm-immutable */
class CacheException extends Exception
class CacheException extends \Exception implements Exception
{
}
2 changes: 1 addition & 1 deletion src/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
namespace Doctrine\DBAL;

/** @psalm-immutable */
class ConnectionException extends Exception
class ConnectionException extends \Exception implements Exception
{
}
3 changes: 2 additions & 1 deletion src/DriverManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\Driver\SQLSrv;
use Doctrine\DBAL\Exception\DriverRequired;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Exception\InvalidDriverClass;
use Doctrine\DBAL\Exception\InvalidWrapperClass;
use Doctrine\DBAL\Exception\UnknownDriver;
Expand Down Expand Up @@ -280,7 +281,7 @@ private static function parseDatabaseUrl(array $params): array
$url = parse_url($url);

if ($url === false) {
throw new Exception('Malformed parameter "url".');
throw new InvalidArgumentException('Malformed parameter "url".');
}

foreach ($url as $param => $value) {
Expand Down
4 changes: 3 additions & 1 deletion src/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

namespace Doctrine\DBAL;

use Throwable;

/** @psalm-immutable */
class Exception extends \Exception
interface Exception extends Throwable
{
}
2 changes: 1 addition & 1 deletion src/Exception/DatabaseRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function sprintf;

/** @psalm-immutable */
class DatabaseRequired extends Exception
class DatabaseRequired extends \Exception implements Exception
{
public static function new(string $methodName): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/DriverException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @psalm-immutable
*/
class DriverException extends Exception implements Driver\Exception
class DriverException extends \Exception implements Exception, Driver\Exception
{
/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/DriverRequired.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function sprintf;

/** @psalm-immutable */
final class DriverRequired extends Exception
final class DriverRequired extends \Exception implements Exception
{
/** @param string|null $url The URL that was provided in the connection parameters (if any). */
public static function new(?string $url = null): self
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
*
* @psalm-immutable
*/
class InvalidArgumentException extends Exception
class InvalidArgumentException extends \InvalidArgumentException implements Exception
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidColumnDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use function sprintf;

/** @psalm-immutable */
final class InvalidColumnDeclaration extends Exception
final class InvalidColumnDeclaration extends \Exception implements Exception
{
public static function fromInvalidColumnType(string $columnName, InvalidColumnType $e): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidColumnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
use Doctrine\DBAL\Exception;

/** @psalm-immutable */
abstract class InvalidColumnType extends Exception
abstract class InvalidColumnType extends \Exception implements Exception
{
}
2 changes: 1 addition & 1 deletion src/Exception/InvalidDriverClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function sprintf;

/** @psalm-immutable */
final class InvalidDriverClass extends Exception
final class InvalidDriverClass extends \Exception implements Exception
{
public static function new(string $driverClass): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidWrapperClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function sprintf;

/** @psalm-immutable */
final class InvalidWrapperClass extends Exception
final class InvalidWrapperClass extends \Exception implements Exception
{
public static function new(string $wrapperClass): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/NoKeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @psalm-immutable
*/
final class NoKeyValue extends Exception
final class NoKeyValue extends \Exception implements Exception
{
public static function fromColumnCount(int $columnCount): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnknownDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use function sprintf;

/** @psalm-immutable */
final class UnknownDriver extends Exception
final class UnknownDriver extends \Exception implements Exception
{
/** @param string[] $knownDrivers */
public static function new(string $unknownDriverName, array $knownDrivers): self
Expand Down
6 changes: 3 additions & 3 deletions src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\DBAL\Event\SchemaDropTableEventArgs;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Exception\InvalidColumnDeclaration;
use Doctrine\DBAL\Exception\InvalidColumnType;
use Doctrine\DBAL\Exception\InvalidColumnType\ColumnLengthRequired;
Expand All @@ -40,7 +41,6 @@
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Exception\TypeNotFound;
use Doctrine\DBAL\Types\Type;
use InvalidArgumentException;
use UnexpectedValueException;

use function addcslashes;
Expand Down Expand Up @@ -364,7 +364,7 @@ public function getDoctrineTypeMapping(string $dbType): string
$dbType = strtolower($dbType);

if (! isset($this->doctrineTypeMapping[$dbType])) {
throw new Exception(sprintf(
throw new InvalidArgumentException(sprintf(
'Unknown database type "%s" requested, %s may not support it.',
$dbType,
static::class,
Expand Down Expand Up @@ -2235,7 +2235,7 @@ public function getTimeFormatString(): string
final public function modifyLimitQuery(string $query, ?int $limit, int $offset = 0): string
{
if ($offset < 0) {
throw new Exception(sprintf(
throw new InvalidArgumentException(sprintf(
'Offset must be a positive integer or zero, %d given.',
$offset,
));
Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/Exception/InvalidPlatformVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\DBAL\Platforms\Exception;

use Doctrine\DBAL\Exception;
use Exception;

use function sprintf;

Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/Exception/NoColumnsSpecifiedForTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\DBAL\Platforms\Exception;

use Doctrine\DBAL\Exception;
use Exception;

use function sprintf;

Expand Down
2 changes: 1 addition & 1 deletion src/Platforms/Exception/NotSupported.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\DBAL\Platforms\Exception;

use Doctrine\DBAL\Exception;
use Exception;

use function sprintf;

Expand Down
4 changes: 3 additions & 1 deletion src/Platforms/Exception/PlatformException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Doctrine\DBAL\Platforms\Exception;

interface PlatformException
use Doctrine\DBAL\Exception;

interface PlatformException extends Exception
{
}
6 changes: 3 additions & 3 deletions src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,17 +543,17 @@ public function getDropTablesSQL(array $tables): array

public function getCreatePrimaryKeySQL(Index $index, string $table): string
{
throw new Exception('Sqlite platform does not support alter primary key.');
throw NotSupported::new(__METHOD__);
}

public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, string $table): string
{
throw new Exception('Sqlite platform does not support alter foreign key.');
throw NotSupported::new(__METHOD__);
}

public function getDropForeignKeySQL(string $foreignKey, string $table): string
{
throw new Exception('Sqlite platform does not support alter foreign key.');
throw NotSupported::new(__METHOD__);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Query/QueryException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
use Doctrine\DBAL\Exception;

/** @psalm-immutable */
class QueryException extends Exception
class QueryException extends \Exception implements Exception
{
}
2 changes: 1 addition & 1 deletion src/Schema/SchemaException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Doctrine\DBAL\Exception;

/** @psalm-immutable */
class SchemaException extends Exception
class SchemaException extends \Exception implements Exception
{
public const TABLE_DOESNT_EXIST = 10;
public const TABLE_ALREADY_EXISTS = 20;
Expand Down
4 changes: 2 additions & 2 deletions src/Schema/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,14 @@ public function getPrimaryKey(): ?Index
*
* @return array<string, Column>
*
* @throws Exception
* @throws SchemaException
*/
public function getPrimaryKeyColumns(): array
{
$primaryKey = $this->getPrimaryKey();

if ($primaryKey === null) {
throw new Exception(sprintf('Table "%s" has no primary key.', $this->getName()));
throw new SchemaException(sprintf('Table "%s" has no primary key.', $this->getName()));
}

return $this->filterColumns($primaryKey->getColumns());
Expand Down
2 changes: 1 addition & 1 deletion src/Types/ConversionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
*
* @psalm-immutable
*/
class ConversionException extends Exception
class ConversionException extends \Exception implements Exception
{
}
2 changes: 1 addition & 1 deletion src/Types/Exception/TypeNotFound.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\DBAL\Types\Exception;

use Doctrine\DBAL\Exception;
use Exception;

use function sprintf;

Expand Down
2 changes: 1 addition & 1 deletion src/Types/Exception/TypeNotRegistered.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Doctrine\DBAL\Types\Exception;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Types\Type;
use Exception;

use function get_debug_type;
use function spl_object_hash;
Expand Down
2 changes: 1 addition & 1 deletion src/Types/Exception/TypesAlreadyExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\DBAL\Types\Exception;

use Doctrine\DBAL\Exception;
use Exception;

use function sprintf;

Expand Down
4 changes: 3 additions & 1 deletion src/Types/Exception/TypesException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Doctrine\DBAL\Types\Exception;

interface TypesException
use Doctrine\DBAL\Exception;

interface TypesException extends Exception
{
}
2 changes: 1 addition & 1 deletion src/Types/Exception/UnknownColumnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Doctrine\DBAL\Types\Exception;

use Doctrine\DBAL\Exception;
use Exception;

use function sprintf;

Expand Down