Skip to content

Commit a2abc86

Browse files
Majkl578morozov
authored andcommitted
Extract exception factory methods into specific exceptions
Extract Doctrine\DBAL\DBALException::notSupported() Extract Doctrine\DBAL\DBALException::invalidPlatformVersionSpecified() Extract Doctrine\DBAL\DBALException::invalidPdoInstance() Extract Doctrine\DBAL\DBALException::invalidWrapperClass() Extract Doctrine\DBAL\DBALException::invalidDriverClass() Extract Doctrine\DBAL\DBALException::invalidTableName() Extract Doctrine\DBAL\DBALException::noColumnsSpecifiedForTable() Extract Doctrine\DBAL\DBALException::typeExists() Extract Doctrine\DBAL\DBALException::typeAlreadyRegistered() Extract Doctrine\DBAL\DBALException::typeNotRegistered() Extract Doctrine\DBAL\DBALException::unknownColumnType() Extract Doctrine\DBAL\DBALException::typeNotFound() Extract Doctrine\DBAL\DBALException::invalidPlatformType() Extract Doctrine\DBAL\DBALException::driverRequired() Extract Doctrine\DBAL\DBALException::unknownDriver() Extract Doctrine\DBAL\DBALException::invalidColumnIndex() Extract Doctrine\DBAL\Exception\ConnectionException::commitFailedRollbackOnly() Extract Doctrine\DBAL\Exception\ConnectionException::noActiveTransaction() Extract Doctrine\DBAL\Exception\ConnectionException::savepointsNotSupported() Extract Doctrine\DBAL\Exception\ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction() Extract Doctrine\DBAL\Exception\InvalidArgumentException::fromEmptyCriteria() Extract Doctrine\DBAL\Type\ConversionException::conversionFailed() Extract Doctrine\DBAL\Type\ConversionException::conversionFailedFormat() Extract Doctrine\DBAL\Type\ConversionException::conversionFailedInvalidType() Extract Doctrine\DBAL\Type\ConversionException::conversionFailedSerialization() Extract Doctrine\DBAL\Query\QueryException::unknownAlias() Extract Doctrine\DBAL\Query\QueryException::nonUniqueAlias() Extract Doctrine\DBAL\Sharding\ShardingException::notImplemented() Extract Doctrine\DBAL\Sharding\ShardingException::missingDefaultFederationName() Extract Doctrine\DBAL\Sharding\ShardingException::missingDefaultDistributionKey() Extract Doctrine\DBAL\Sharding\ShardingException::activeTransaction() Extract Doctrine\DBAL\Sharding\ShardingException::noShardDistributionValue() Extract Doctrine\DBAL\Sharding\ShardingException::missingDistributionType() Extract Doctrine\DBAL\Cache\CacheException::noCacheKey() Extract Doctrine\DBAL\Cache\CacheException::noResultDriverConfigured() Extract Doctrine\DBAL\Schema\SchemaException::tableDoesNotExist() Extract Doctrine\DBAL\Schema\SchemaException::indexNameInvalid() Extract Doctrine\DBAL\Schema\SchemaException::indexDoesNotExist() Extract Doctrine\DBAL\Schema\SchemaException::indexAlreadyExists() Extract Doctrine\DBAL\Schema\SchemaException::columnDoesNotExist() Extract Doctrine\DBAL\Schema\SchemaException::namespaceAlreadyExists() Extract Doctrine\DBAL\Schema\SchemaException::tableAlreadyExists() Extract Doctrine\DBAL\Schema\SchemaException::columnAlreadyExists() Extract Doctrine\DBAL\Schema\SchemaException::sequenceAlreadyExists() Extract Doctrine\DBAL\Schema\SchemaException::sequenceDoesNotExist() Extract Doctrine\DBAL\Schema\SchemaException::uniqueConstraintDoesNotExist() Extract Doctrine\DBAL\Schema\SchemaException::foreignKeyDoesNotExist() Extract Doctrine\DBAL\Schema\SchemaException::namedForeignKeyRequired() Extract Doctrine\DBAL\SQLParserUtilsException::missingParam() Extract Doctrine\DBAL\SQLParserUtilsException::missingType() Drop Doctrine\DBAL\DBALException::invalidPlatformSpecified() Drop Doctrine\DBAL\DBALException::limitOffsetInvalid() Drop Doctrine\DBAL\Schema\SchemaException::alterTableChangeNotSupported()
1 parent 6555a46 commit a2abc86

File tree

113 files changed

+1451
-811
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+1451
-811
lines changed

lib/Doctrine/DBAL/Cache/ArrayStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace Doctrine\DBAL\Cache;
66

77
use ArrayIterator;
8-
use Doctrine\DBAL\DBALException;
98
use Doctrine\DBAL\Driver\ResultStatement;
9+
use Doctrine\DBAL\Exception\InvalidColumnIndex;
1010
use Doctrine\DBAL\FetchMode;
1111
use InvalidArgumentException;
1212
use IteratorAggregate;
@@ -149,7 +149,7 @@ public function fetchColumn($columnIndex = 0)
149149
}
150150

151151
if (! array_key_exists($columnIndex, $row)) {
152-
throw DBALException::invalidColumnIndex($columnIndex, count($row));
152+
throw InvalidColumnIndex::new($columnIndex, count($row));
153153
}
154154

155155
return $row[$columnIndex];

lib/Doctrine/DBAL/Cache/CacheException.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,4 @@
88

99
class CacheException extends DBALException
1010
{
11-
/**
12-
* @return \Doctrine\DBAL\Cache\CacheException
13-
*/
14-
public static function noCacheKey()
15-
{
16-
return new self('No cache key was set.');
17-
}
18-
19-
/**
20-
* @return \Doctrine\DBAL\Cache\CacheException
21-
*/
22-
public static function noResultDriverConfigured()
23-
{
24-
return new self('Trying to cache a query but no result driver is configured.');
25-
}
2611
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Cache\Exception;
6+
7+
use Doctrine\DBAL\Cache\CacheException;
8+
9+
final class NoCacheKey extends CacheException
10+
{
11+
public static function new() : self
12+
{
13+
return new self('No cache key was set.');
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Cache\Exception;
6+
7+
use Doctrine\DBAL\Cache\CacheException;
8+
9+
final class NoResultDriverConfigured extends CacheException
10+
{
11+
public static function new() : self
12+
{
13+
return new self('Trying to cache a query but no result driver is configured.');
14+
}
15+
}

lib/Doctrine/DBAL/Cache/QueryCacheProfile.php

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

77
use Doctrine\Common\Cache\Cache;
8+
use Doctrine\DBAL\Cache\Exception\NoCacheKey;
89
use function hash;
910
use function serialize;
1011
use function sha1;
@@ -60,7 +61,7 @@ public function getLifetime()
6061
public function getCacheKey()
6162
{
6263
if ($this->cacheKey === null) {
63-
throw CacheException::noCacheKey();
64+
throw NoCacheKey::new();
6465
}
6566

6667
return $this->cacheKey;

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
use ArrayIterator;
88
use Doctrine\Common\Cache\Cache;
9-
use Doctrine\DBAL\DBALException;
109
use Doctrine\DBAL\Driver\ResultStatement;
10+
use Doctrine\DBAL\Exception\InvalidColumnIndex;
1111
use Doctrine\DBAL\FetchMode;
1212
use InvalidArgumentException;
1313
use IteratorAggregate;
@@ -192,7 +192,7 @@ public function fetchColumn($columnIndex = 0)
192192
}
193193

194194
if (! array_key_exists($columnIndex, $row)) {
195-
throw DBALException::invalidColumnIndex($columnIndex, count($row));
195+
throw InvalidColumnIndex::new($columnIndex, count($row));
196196
}
197197

198198
return $row[$columnIndex];

lib/Doctrine/DBAL/Connection.php

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\Common\EventManager;
99
use Doctrine\DBAL\Cache\ArrayStatement;
1010
use Doctrine\DBAL\Cache\CacheException;
11+
use Doctrine\DBAL\Cache\Exception\NoResultDriverConfigured;
1112
use Doctrine\DBAL\Cache\QueryCacheProfile;
1213
use Doctrine\DBAL\Cache\ResultCacheStatement;
1314
use Doctrine\DBAL\Driver\Connection as DriverConnection;
@@ -16,7 +17,13 @@
1617
use Doctrine\DBAL\Driver\ResultStatement;
1718
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1819
use Doctrine\DBAL\Driver\Statement as DriverStatement;
20+
use Doctrine\DBAL\Exception\CommitFailedRollbackOnly;
21+
use Doctrine\DBAL\Exception\EmptyCriteriaNotAllowed;
1922
use Doctrine\DBAL\Exception\InvalidArgumentException;
23+
use Doctrine\DBAL\Exception\InvalidPlatformType;
24+
use Doctrine\DBAL\Exception\MayNotAlterNestedTransactionWithSavepointsInTransaction;
25+
use Doctrine\DBAL\Exception\NoActiveTransaction;
26+
use Doctrine\DBAL\Exception\SavepointsNotSupported;
2027
use Doctrine\DBAL\Platforms\AbstractPlatform;
2128
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
2229
use Doctrine\DBAL\Query\QueryBuilder;
@@ -198,7 +205,7 @@ public function __construct(
198205

199206
if (isset($params['platform'])) {
200207
if (! $params['platform'] instanceof Platforms\AbstractPlatform) {
201-
throw DBALException::invalidPlatformType($params['platform']);
208+
throw InvalidPlatformType::new($params['platform']);
202209
}
203210

204211
$this->platform = $params['platform'];
@@ -651,7 +658,7 @@ private function addIdentifierCondition(
651658
public function delete($tableExpression, array $identifier, array $types = [])
652659
{
653660
if (empty($identifier)) {
654-
throw InvalidArgumentException::fromEmptyCriteria();
661+
throw EmptyCriteriaNotAllowed::new();
655662
}
656663

657664
$columns = $values = $conditions = [];
@@ -924,7 +931,7 @@ public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qc
924931
$resultCache = $qcp->getResultCacheDriver() ?? $this->_config->getResultCacheImpl();
925932

926933
if ($resultCache === null) {
927-
throw CacheException::noResultDriverConfigured();
934+
throw NoResultDriverConfigured::new();
928935
}
929936

930937
$connectionParams = $this->getParams();
@@ -1134,11 +1141,11 @@ public function transactional(Closure $func)
11341141
public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints)
11351142
{
11361143
if ($this->transactionNestingLevel > 0) {
1137-
throw ConnectionException::mayNotAlterNestedTransactionWithSavepointsInTransaction();
1144+
throw MayNotAlterNestedTransactionWithSavepointsInTransaction::new();
11381145
}
11391146

11401147
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
1141-
throw ConnectionException::savepointsNotSupported();
1148+
throw SavepointsNotSupported::new();
11421149
}
11431150

11441151
$this->nestTransactionsWithSavepoints = (bool) $nestTransactionsWithSavepoints;
@@ -1200,11 +1207,10 @@ public function beginTransaction() : void
12001207
public function commit() : void
12011208
{
12021209
if ($this->transactionNestingLevel === 0) {
1203-
throw ConnectionException::noActiveTransaction();
1210+
throw NoActiveTransaction::new();
12041211
}
1205-
12061212
if ($this->isRollbackOnly) {
1207-
throw ConnectionException::commitFailedRollbackOnly();
1213+
throw CommitFailedRollbackOnly::new();
12081214
}
12091215

12101216
$result = true;
@@ -1265,7 +1271,7 @@ private function commitAll() : void
12651271
public function rollBack() : void
12661272
{
12671273
if ($this->transactionNestingLevel === 0) {
1268-
throw ConnectionException::noActiveTransaction();
1274+
throw NoActiveTransaction::new();
12691275
}
12701276

12711277
$connection = $this->getWrappedConnection();
@@ -1309,7 +1315,7 @@ public function rollBack() : void
13091315
public function createSavepoint($savepoint)
13101316
{
13111317
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
1312-
throw ConnectionException::savepointsNotSupported();
1318+
throw SavepointsNotSupported::new();
13131319
}
13141320

13151321
$this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint));
@@ -1327,7 +1333,7 @@ public function createSavepoint($savepoint)
13271333
public function releaseSavepoint($savepoint)
13281334
{
13291335
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
1330-
throw ConnectionException::savepointsNotSupported();
1336+
throw SavepointsNotSupported::new();
13311337
}
13321338

13331339
if (! $this->platform->supportsReleaseSavepoints()) {
@@ -1349,7 +1355,7 @@ public function releaseSavepoint($savepoint)
13491355
public function rollbackSavepoint($savepoint)
13501356
{
13511357
if (! $this->getDatabasePlatform()->supportsSavepoints()) {
1352-
throw ConnectionException::savepointsNotSupported();
1358+
throw SavepointsNotSupported::new();
13531359
}
13541360

13551361
$this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint));
@@ -1393,7 +1399,7 @@ public function getSchemaManager()
13931399
public function setRollbackOnly()
13941400
{
13951401
if ($this->transactionNestingLevel === 0) {
1396-
throw ConnectionException::noActiveTransaction();
1402+
throw NoActiveTransaction::new();
13971403
}
13981404
$this->isRollbackOnly = true;
13991405
}
@@ -1408,7 +1414,7 @@ public function setRollbackOnly()
14081414
public function isRollbackOnly()
14091415
{
14101416
if ($this->transactionNestingLevel === 0) {
1411-
throw ConnectionException::noActiveTransaction();
1417+
throw NoActiveTransaction::new();
14121418
}
14131419

14141420
return $this->isRollbackOnly;

lib/Doctrine/DBAL/ConnectionException.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,4 @@
66

77
class ConnectionException extends DBALException
88
{
9-
/**
10-
* @return \Doctrine\DBAL\ConnectionException
11-
*/
12-
public static function commitFailedRollbackOnly()
13-
{
14-
return new self('Transaction commit failed because the transaction has been marked for rollback only.');
15-
}
16-
17-
/**
18-
* @return \Doctrine\DBAL\ConnectionException
19-
*/
20-
public static function noActiveTransaction()
21-
{
22-
return new self('There is no active transaction.');
23-
}
24-
25-
/**
26-
* @return \Doctrine\DBAL\ConnectionException
27-
*/
28-
public static function savepointsNotSupported()
29-
{
30-
return new self('Savepoints are not supported by this driver.');
31-
}
32-
33-
/**
34-
* @return \Doctrine\DBAL\ConnectionException
35-
*/
36-
public static function mayNotAlterNestedTransactionWithSavepointsInTransaction()
37-
{
38-
return new self('May not alter the nested transaction with savepoints behavior while a transaction is open.');
39-
}
409
}

0 commit comments

Comments
 (0)