Skip to content

Commit 4bd24c8

Browse files
committed
Convert Doctrine\DBAL\Exception to an interface
1 parent f92d354 commit 4bd24c8

30 files changed

+45
-34
lines changed

UPGRADE.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ awareness about deprecated code.
88

99
# Upgrade to 4.0
1010

11+
## BC BREAK: The base exception class has been converted to an interface
12+
13+
The Doctrine\DBAL\Exception class is now an interface.
14+
1115
## BC BREAK: removed misspelled isFullfilledBy() method
1216

1317
This method's name was spelled incorrectly. Use `isFulfilledBy` instead.

src/Cache/CacheException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
use Doctrine\DBAL\Exception;
88

99
/** @psalm-immutable */
10-
class CacheException extends Exception
10+
class CacheException extends \Exception implements Exception
1111
{
1212
}

src/ConnectionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
namespace Doctrine\DBAL;
66

77
/** @psalm-immutable */
8-
class ConnectionException extends Exception
8+
class ConnectionException extends \Exception implements Exception
99
{
1010
}

src/DriverManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Doctrine\DBAL\Driver\PDO;
1212
use Doctrine\DBAL\Driver\SQLSrv;
1313
use Doctrine\DBAL\Exception\DriverRequired;
14+
use Doctrine\DBAL\Exception\InvalidArgumentException;
1415
use Doctrine\DBAL\Exception\InvalidDriverClass;
1516
use Doctrine\DBAL\Exception\InvalidWrapperClass;
1617
use Doctrine\DBAL\Exception\UnknownDriver;
@@ -280,7 +281,7 @@ private static function parseDatabaseUrl(array $params): array
280281
$url = parse_url($url);
281282

282283
if ($url === false) {
283-
throw new Exception('Malformed parameter "url".');
284+
throw new InvalidArgumentException('Malformed parameter "url".');
284285
}
285286

286287
foreach ($url as $param => $value) {

src/Exception.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
namespace Doctrine\DBAL;
66

7+
use Throwable;
8+
79
/** @psalm-immutable */
8-
class Exception extends \Exception
10+
interface Exception extends Throwable
911
{
1012
}

src/Exception/DatabaseRequired.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use function sprintf;
1010

1111
/** @psalm-immutable */
12-
class DatabaseRequired extends Exception
12+
class DatabaseRequired extends \Exception implements Exception
1313
{
1414
public static function new(string $methodName): self
1515
{

src/Exception/DriverException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
* @psalm-immutable
1717
*/
18-
class DriverException extends Exception implements Driver\Exception
18+
class DriverException extends \Exception implements Exception, Driver\Exception
1919
{
2020
/**
2121
* @internal

src/Exception/DriverRequired.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use function sprintf;
1010

1111
/** @psalm-immutable */
12-
final class DriverRequired extends Exception
12+
final class DriverRequired extends \Exception implements Exception
1313
{
1414
/** @param string|null $url The URL that was provided in the connection parameters (if any). */
1515
public static function new(?string $url = null): self

src/Exception/InvalidArgumentException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
*
1212
* @psalm-immutable
1313
*/
14-
class InvalidArgumentException extends Exception
14+
class InvalidArgumentException extends \InvalidArgumentException implements Exception
1515
{
1616
}

src/Exception/InvalidColumnDeclaration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use function sprintf;
1010

1111
/** @psalm-immutable */
12-
final class InvalidColumnDeclaration extends Exception
12+
final class InvalidColumnDeclaration extends \Exception implements Exception
1313
{
1414
public static function fromInvalidColumnType(string $columnName, InvalidColumnType $e): self
1515
{

src/Exception/InvalidColumnType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
use Doctrine\DBAL\Exception;
88

99
/** @psalm-immutable */
10-
abstract class InvalidColumnType extends Exception
10+
abstract class InvalidColumnType extends \Exception implements Exception
1111
{
1212
}

src/Exception/InvalidDriverClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use function sprintf;
1111

1212
/** @psalm-immutable */
13-
final class InvalidDriverClass extends Exception
13+
final class InvalidDriverClass extends \Exception implements Exception
1414
{
1515
public static function new(string $driverClass): self
1616
{

src/Exception/InvalidWrapperClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use function sprintf;
1111

1212
/** @psalm-immutable */
13-
final class InvalidWrapperClass extends Exception
13+
final class InvalidWrapperClass extends \Exception implements Exception
1414
{
1515
public static function new(string $wrapperClass): self
1616
{

src/Exception/NoKeyValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* @psalm-immutable
1515
*/
16-
final class NoKeyValue extends Exception
16+
final class NoKeyValue extends \Exception implements Exception
1717
{
1818
public static function fromColumnCount(int $columnCount): self
1919
{

src/Exception/UnknownDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use function sprintf;
1111

1212
/** @psalm-immutable */
13-
final class UnknownDriver extends Exception
13+
final class UnknownDriver extends \Exception implements Exception
1414
{
1515
/** @param string[] $knownDrivers */
1616
public static function new(string $unknownDriverName, array $knownDrivers): self

src/Platforms/AbstractPlatform.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\DBAL\Event\SchemaDropTableEventArgs;
1717
use Doctrine\DBAL\Events;
1818
use Doctrine\DBAL\Exception;
19+
use Doctrine\DBAL\Exception\InvalidArgumentException;
1920
use Doctrine\DBAL\Exception\InvalidColumnDeclaration;
2021
use Doctrine\DBAL\Exception\InvalidColumnType;
2122
use Doctrine\DBAL\Exception\InvalidColumnType\ColumnLengthRequired;
@@ -40,7 +41,6 @@
4041
use Doctrine\DBAL\Types;
4142
use Doctrine\DBAL\Types\Exception\TypeNotFound;
4243
use Doctrine\DBAL\Types\Type;
43-
use InvalidArgumentException;
4444
use UnexpectedValueException;
4545

4646
use function addcslashes;
@@ -364,7 +364,7 @@ public function getDoctrineTypeMapping(string $dbType): string
364364
$dbType = strtolower($dbType);
365365

366366
if (! isset($this->doctrineTypeMapping[$dbType])) {
367-
throw new Exception(sprintf(
367+
throw new InvalidArgumentException(sprintf(
368368
'Unknown database type "%s" requested, %s may not support it.',
369369
$dbType,
370370
static::class,
@@ -2235,7 +2235,7 @@ public function getTimeFormatString(): string
22352235
final public function modifyLimitQuery(string $query, ?int $limit, int $offset = 0): string
22362236
{
22372237
if ($offset < 0) {
2238-
throw new Exception(sprintf(
2238+
throw new InvalidArgumentException(sprintf(
22392239
'Offset must be a positive integer or zero, %d given.',
22402240
$offset,
22412241
));

src/Platforms/Exception/InvalidPlatformVersion.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Doctrine\DBAL\Platforms\Exception;
66

7-
use Doctrine\DBAL\Exception;
7+
use Exception;
88

99
use function sprintf;
1010

src/Platforms/Exception/NoColumnsSpecifiedForTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Doctrine\DBAL\Platforms\Exception;
66

7-
use Doctrine\DBAL\Exception;
7+
use Exception;
88

99
use function sprintf;
1010

src/Platforms/Exception/NotSupported.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Doctrine\DBAL\Platforms\Exception;
66

7-
use Doctrine\DBAL\Exception;
7+
use Exception;
88

99
use function sprintf;
1010

src/Platforms/Exception/PlatformException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Doctrine\DBAL\Platforms\Exception;
66

7-
interface PlatformException
7+
use Doctrine\DBAL\Exception;
8+
9+
interface PlatformException extends Exception
810
{
911
}

src/Platforms/SQLitePlatform.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -543,17 +543,17 @@ public function getDropTablesSQL(array $tables): array
543543

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

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

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

559559
/**

src/Query/QueryException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
use Doctrine\DBAL\Exception;
88

99
/** @psalm-immutable */
10-
class QueryException extends Exception
10+
class QueryException extends \Exception implements Exception
1111
{
1212
}

src/Schema/SchemaException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Doctrine\DBAL\Exception;
88

99
/** @psalm-immutable */
10-
class SchemaException extends Exception
10+
class SchemaException extends \Exception implements Exception
1111
{
1212
public const TABLE_DOESNT_EXIST = 10;
1313
public const TABLE_ALREADY_EXISTS = 20;

src/Schema/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,14 @@ public function getPrimaryKey(): ?Index
516516
*
517517
* @return array<string, Column>
518518
*
519-
* @throws Exception
519+
* @throws SchemaException
520520
*/
521521
public function getPrimaryKeyColumns(): array
522522
{
523523
$primaryKey = $this->getPrimaryKey();
524524

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

529529
return $this->filterColumns($primaryKey->getColumns());

src/Types/ConversionException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
*
1212
* @psalm-immutable
1313
*/
14-
class ConversionException extends Exception
14+
class ConversionException extends \Exception implements Exception
1515
{
1616
}

src/Types/Exception/TypeNotFound.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Doctrine\DBAL\Types\Exception;
66

7-
use Doctrine\DBAL\Exception;
7+
use Exception;
88

99
use function sprintf;
1010

src/Types/Exception/TypeNotRegistered.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Doctrine\DBAL\Types\Exception;
66

7-
use Doctrine\DBAL\Exception;
87
use Doctrine\DBAL\Types\Type;
8+
use Exception;
99

1010
use function get_debug_type;
1111
use function spl_object_hash;

src/Types/Exception/TypesAlreadyExists.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Doctrine\DBAL\Types\Exception;
66

7-
use Doctrine\DBAL\Exception;
7+
use Exception;
88

99
use function sprintf;
1010

src/Types/Exception/TypesException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Doctrine\DBAL\Types\Exception;
66

7-
interface TypesException
7+
use Doctrine\DBAL\Exception;
8+
9+
interface TypesException extends Exception
810
{
911
}

src/Types/Exception/UnknownColumnType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Doctrine\DBAL\Types\Exception;
66

7-
use Doctrine\DBAL\Exception;
7+
use Exception;
88

99
use function sprintf;
1010

0 commit comments

Comments
 (0)