Skip to content
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

Switch to PHP 8.0 syntax via Rector #5541

Merged
merged 2 commits into from
Jul 28, 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
6 changes: 1 addition & 5 deletions src/Cache/ArrayResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,14 @@
*/
final class ArrayResult implements Result
{
/** @var list<array<string, mixed>> */
private array $data;

private int $columnCount = 0;
private int $num = 0;

/**
* @param list<array<string, mixed>> $data
*/
public function __construct(array $data)
public function __construct(private array $data)
{
$this->data = $data;
if (count($data) === 0) {
return;
}
Expand Down
15 changes: 3 additions & 12 deletions src/Cache/QueryCacheProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,11 @@
*/
class QueryCacheProfile
{
private ?CacheItemPoolInterface $resultCache = null;

private int $lifetime;

private ?string $cacheKey = null;

public function __construct(
int $lifetime = 0,
?string $cacheKey = null,
?CacheItemPoolInterface $resultCache = null
private int $lifetime = 0,
private ?string $cacheKey = null,
private ?CacheItemPoolInterface $resultCache = null
) {
$this->lifetime = $lifetime;
$this->cacheKey = $cacheKey;
$this->resultCache = $resultCache;
}

public function getResultCache(): ?CacheItemPoolInterface
Expand Down
35 changes: 11 additions & 24 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ class Connection implements ServerVersionProvider
private ?ExceptionConverter $exceptionConverter = null;
private ?Parser $parser = null;

/**
* The used DBAL driver.
*/
protected Driver $_driver;

/**
* Flag that indicates whether the current transaction is marked for rollback only.
*/
Expand All @@ -140,19 +135,12 @@ class Connection implements ServerVersionProvider
*/
public function __construct(
array $params,
Driver $driver,
protected Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
) {
$this->_driver = $driver;
$this->params = $params;

// Create default config and event manager if none given
$config ??= new Configuration();
$eventManager ??= new EventManager();

$this->_config = $config;
$this->_eventManager = $eventManager;
$this->_config = $config ?? new Configuration();
$this->_eventManager = $eventManager ?? new EventManager();

if (isset($params['platform'])) {
if (! $params['platform'] instanceof Platforms\AbstractPlatform) {
Expand All @@ -163,7 +151,8 @@ public function __construct(
$this->platform->setEventManager($this->_eventManager);
}

$this->autoCommit = $config->getAutoCommit();
$this->params = $params;
$this->autoCommit = $this->_config->getAutoCommit();
}

/**
Expand Down Expand Up @@ -204,7 +193,7 @@ public function getDatabase(): ?string
*/
public function getDriver(): Driver
{
return $this->_driver;
return $this->driver;
}

/**
Expand Down Expand Up @@ -237,7 +226,7 @@ public function getDatabasePlatform(): AbstractPlatform
$versionProvider = new StaticServerVersionProvider($this->params['serverVersion']);
}

$this->platform = $this->_driver->getDatabasePlatform($versionProvider);
$this->platform = $this->driver->getDatabasePlatform($versionProvider);
$this->platform->setEventManager($this->_eventManager);
}

Expand All @@ -264,7 +253,7 @@ protected function connect(): DriverConnection
}

try {
$connection = $this->_conn = $this->_driver->connect($this->params);
$connection = $this->_conn = $this->driver->connect($this->params);
} catch (Driver\Exception $e) {
throw $this->convertException($e);
}
Expand Down Expand Up @@ -319,7 +308,7 @@ private function getServerVersionConnection(): DriverConnection

try {
return $this->connect();
} catch (Exception $_) {
} catch (Exception) {
// Either the platform does not support database-less connections
// or something else went wrong.
throw $e;
Expand Down Expand Up @@ -401,7 +390,7 @@ public function fetchAssociative(string $query, array $params = [], array $types
*
* @throws Exception
*/
public function fetchNumeric(string $query, array $params = [], array $types = [])
public function fetchNumeric(string $query, array $params = [], array $types = []): array|false
{
return $this->executeQuery($query, $params, $types)->fetchNumeric();
}
Expand Down Expand Up @@ -1056,8 +1045,6 @@ public function setNestTransactionsWithSavepoints(bool $nestTransactionsWithSave
* Gets if nested transactions should use savepoints.
*
* @deprecated No replacement planned
*
* @return true
*/
public function getNestTransactionsWithSavepoints(): bool
{
Expand Down Expand Up @@ -1474,7 +1461,7 @@ private function handleDriverException(
Driver\Exception $driverException,
?Query $query
): DriverException {
$this->exceptionConverter ??= $this->_driver->getExceptionConverter();
$this->exceptionConverter ??= $this->driver->getExceptionConverter();
$exception = $this->exceptionConverter->convert($driverException, $query);

if ($exception instanceof ConnectionLost) {
Expand Down
5 changes: 1 addition & 4 deletions src/Connection/StaticServerVersionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class StaticServerVersionProvider implements ServerVersionProvider
{
private string $version;

public function __construct(string $version)
public function __construct(private string $version)
{
$this->version = $version;
}

public function getServerVersion(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Connections/PrimaryReadReplicaConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ protected function connectTo(string $connectionName): DriverConnection
$connectionParams = $this->chooseConnectionConfiguration($connectionName, $params);

try {
return $this->_driver->connect($connectionParams);
return $this->driver->connect($connectionParams);
} catch (DriverException $e) {
throw $this->convertException($e);
}
Expand Down
50 changes: 16 additions & 34 deletions src/Driver/API/IBMDB2/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,21 @@ final class ExceptionConverter implements ExceptionConverterInterface
{
public function convert(Exception $exception, ?Query $query): DriverException
{
switch ($exception->getCode()) {
case -104:
return new SyntaxErrorException($exception, $query);

case -203:
return new NonUniqueFieldNameException($exception, $query);

case -204:
return new TableNotFoundException($exception, $query);

case -206:
return new InvalidFieldNameException($exception, $query);

case -407:
return new NotNullConstraintViolationException($exception, $query);

case -530:
case -531:
case -532:
case -20356:
return new ForeignKeyConstraintViolationException($exception, $query);

case -601:
return new TableExistsException($exception, $query);

case -803:
return new UniqueConstraintViolationException($exception, $query);

case -1336:
case -30082:
return new ConnectionException($exception, $query);
}

return new DriverException($exception, $query);
return match ($exception->getCode()) {
-104 => new SyntaxErrorException($exception, $query),
-203 => new NonUniqueFieldNameException($exception, $query),
-204 => new TableNotFoundException($exception, $query),
-206 => new InvalidFieldNameException($exception, $query),
-407 => new NotNullConstraintViolationException($exception, $query),
-530,
-531,
-532,
-20356 => new ForeignKeyConstraintViolationException($exception, $query),
-601 => new TableExistsException($exception, $query),
-803 => new UniqueConstraintViolationException($exception, $query),
-1336,
-30082 => new ConnectionException($exception, $query),
default => new DriverException($exception, $query),
};
}
}
142 changes: 58 additions & 84 deletions src/Driver/API/MySQL/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,89 +33,63 @@ final class ExceptionConverter implements ExceptionConverterInterface
*/
public function convert(Exception $exception, ?Query $query): DriverException
{
switch ($exception->getCode()) {
case 1008:
return new DatabaseDoesNotExist($exception, $query);

case 1213:
return new DeadlockException($exception, $query);

case 1205:
return new LockWaitTimeoutException($exception, $query);

case 1050:
return new TableExistsException($exception, $query);

case 1051:
case 1146:
return new TableNotFoundException($exception, $query);

case 1216:
case 1217:
case 1451:
case 1452:
case 1701:
return new ForeignKeyConstraintViolationException($exception, $query);

case 1062:
case 1557:
case 1569:
case 1586:
return new UniqueConstraintViolationException($exception, $query);

case 1054:
case 1166:
case 1611:
return new InvalidFieldNameException($exception, $query);

case 1052:
case 1060:
case 1110:
return new NonUniqueFieldNameException($exception, $query);

case 1064:
case 1149:
case 1287:
case 1341:
case 1342:
case 1343:
case 1344:
case 1382:
case 1479:
case 1541:
case 1554:
case 1626:
return new SyntaxErrorException($exception, $query);

case 1044:
case 1045:
case 1046:
case 1049:
case 1095:
case 1142:
case 1143:
case 1227:
case 1370:
case 1429:
case 2002:
case 2005:
case 2054:
return new ConnectionException($exception, $query);

case 2006:
return new ConnectionLost($exception, $query);

case 1048:
case 1121:
case 1138:
case 1171:
case 1252:
case 1263:
case 1364:
case 1566:
return new NotNullConstraintViolationException($exception, $query);
}

return new DriverException($exception, $query);
return match ($exception->getCode()) {
1008 => new DatabaseDoesNotExist($exception, $query),
1213 => new DeadlockException($exception, $query),
1205 => new LockWaitTimeoutException($exception, $query),
1050 => new TableExistsException($exception, $query),
1051,
1146 => new TableNotFoundException($exception, $query),
1216,
1217,
1451,
1452,
1701 => new ForeignKeyConstraintViolationException($exception, $query),
1062,
1557,
1569,
1586 => new UniqueConstraintViolationException($exception, $query),
1054,
1166,
1611 => new InvalidFieldNameException($exception, $query),
1052,
1060,
1110 => new NonUniqueFieldNameException($exception, $query),
1064,
1149,
1287,
1341,
1342,
1343,
1344,
1382,
1479,
1541,
1554,
1626 => new SyntaxErrorException($exception, $query),
1044,
1045,
1046,
1049,
1095,
1142,
1143,
1227,
1370,
1429,
2002,
2005,
2054 => new ConnectionException($exception, $query),
2006 => new ConnectionLost($exception, $query),
1048,
1121,
1138,
1171,
1252,
1263,
1364,
1566 => new NotNullConstraintViolationException($exception, $query),
default => new DriverException($exception, $query),
};
}
}
Loading