Skip to content

Commit

Permalink
Upgrade to doctrine/coding-standard 10
Browse files Browse the repository at this point in the history
One rule is excluded temporarily, pending a discussion on the standard
repository.
  • Loading branch information
greg0ire committed Aug 29, 2022
1 parent 035b4a8 commit 4bb2c0b
Show file tree
Hide file tree
Showing 310 changed files with 1,513 additions and 2,602 deletions.
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
<exclude name="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants.DisallowedLateStaticBindingForConstant"/>
<exclude name="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing.IncorrectLinesCountAfterLastControlStructure"/>
<!-- https://github.com/doctrine/coding-standard/issues/288 -->
<exclude name="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat.DisallowedShortNullable"/>

<exclude name="PSR2.Methods.MethodDeclaration.Underscore"/>
<!-- https://github.com/slevomat/coding-standard/issues/867 -->
Expand Down
4 changes: 1 addition & 3 deletions src/ArrayParameters/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Throwable;

/**
* @internal
*/
/** @internal */
interface Exception extends Throwable
{
}
6 changes: 2 additions & 4 deletions src/ArrayParameters/Exception/MissingNamedParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@

use function sprintf;

/**
* @psalm-immutable
*/
/** @psalm-immutable */
class MissingNamedParameter extends LogicException implements Exception
{
public static function new(string $name): self
{
return new self(
sprintf('Named parameter "%s" does not have a bound value.', $name)
sprintf('Named parameter "%s" does not have a bound value.', $name),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MissingPositionalParameter extends LogicException implements Exception
public static function new(int $index): self
{
return new self(
sprintf('Positional parameter at index %d does not have a bound value.', $index)
sprintf('Positional parameter at index %d does not have a bound value.', $index),
);
}
}
12 changes: 3 additions & 9 deletions src/Cache/ArrayResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,13 @@
use function count;
use function reset;

/**
* @internal The class is internal to the caching layer implementation.
*/
/** @internal The class is internal to the caching layer implementation. */
final class ArrayResult implements Result
{
private readonly int $columnCount;
private int $num = 0;

/**
* @param list<array<string, mixed>> $data
*/
/** @param list<array<string, mixed>> $data */
public function __construct(private array $data)
{
$this->columnCount = $data === [] ? 0 : count($data[0]);
Expand Down Expand Up @@ -93,9 +89,7 @@ public function free(): void
$this->data = [];
}

/**
* @return array<string, mixed>|false
*/
/** @return array<string, mixed>|false */
private function fetch(): array|false
{
if (! isset($this->data[$this->num])) {
Expand Down
4 changes: 1 addition & 3 deletions src/Cache/CacheException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Doctrine\DBAL\Exception;

/**
* @psalm-immutable
*/
/** @psalm-immutable */
class CacheException extends Exception
{
}
4 changes: 1 addition & 3 deletions src/Cache/Exception/NoCacheKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Doctrine\DBAL\Cache\CacheException;

/**
* @psalm-immutable
*/
/** @psalm-immutable */
final class NoCacheKey extends CacheException
{
public static function new(): self
Expand Down
4 changes: 1 addition & 3 deletions src/Cache/Exception/NoResultDriverConfigured.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@

use Doctrine\DBAL\Cache\CacheException;

/**
* @psalm-immutable
*/
/** @psalm-immutable */
final class NoResultDriverConfigured extends CacheException
{
public static function new(): self
Expand Down
6 changes: 2 additions & 4 deletions src/Cache/QueryCacheProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class QueryCacheProfile
public function __construct(
private readonly int $lifetime = 0,
private readonly ?string $cacheKey = null,
private readonly ?CacheItemPoolInterface $resultCache = null
private readonly ?CacheItemPoolInterface $resultCache = null,
) {
}

Expand All @@ -37,9 +37,7 @@ public function getLifetime(): int
return $this->lifetime;
}

/**
* @throws CacheException
*/
/** @throws CacheException */
public function getCacheKey(): string
{
if ($this->cacheKey === null) {
Expand Down
4 changes: 1 addition & 3 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ public function setMiddlewares(array $middlewares): self
return $this;
}

/**
* @return Middleware[]
*/
/** @return Middleware[] */
public function getMiddlewares(): array
{
return $this->middlewares;
Expand Down
36 changes: 14 additions & 22 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function __construct(
array $params,
protected Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
?EventManager $eventManager = null,
) {
$this->_config = $config ?? new Configuration();
$this->_eventManager = $eventManager ?? new EventManager();
Expand Down Expand Up @@ -436,7 +436,7 @@ private function addCriteriaCondition(
array $criteria,
array &$columns,
array &$values,
array &$conditions
array &$conditions,
): void {
foreach ($criteria as $columnName => $value) {
if ($value === null) {
Expand Down Expand Up @@ -477,7 +477,7 @@ public function delete(string $table, array $criteria = [], array $types = []):
return $this->executeStatement(
$sql,
$values,
is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types
is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types,
);
}

Expand Down Expand Up @@ -586,7 +586,7 @@ public function insert(string $table, array $data, array $types = []): int|strin
'INSERT INTO ' . $table . ' (' . implode(', ', $columns) . ')' .
' VALUES (' . implode(', ', $set) . ')',
$values,
is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types
is_string(key($types)) ? $this->extractTypeValues($columns, $types) : $types,
);
}

Expand Down Expand Up @@ -829,7 +829,7 @@ public function executeQuery(
string $sql,
array $params = [],
array $types = [],
?QueryCacheProfile $qcp = null
?QueryCacheProfile $qcp = null,
): Result {
if ($qcp !== null) {
return $this->executeCacheQuery($sql, $params, $types, $qcp);
Expand Down Expand Up @@ -1015,15 +1015,15 @@ public function setNestTransactionsWithSavepoints(bool $nestTransactionsWithSave
if (! $nestTransactionsWithSavepoints) {
throw new InvalidArgumentException(sprintf(
'Calling %s with false to enable nesting transactions without savepoints is no longer supported.',
__METHOD__
__METHOD__,
));
}

Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5383',
'%s is deprecated and will be removed in 5.0',
__METHOD__
__METHOD__,
);
}

Expand All @@ -1038,7 +1038,7 @@ public function getNestTransactionsWithSavepoints(): bool
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5383',
'%s is deprecated and will be removed in 5.0',
__METHOD__
__METHOD__,
);

return true;
Expand All @@ -1052,9 +1052,7 @@ protected function _getNestedTransactionSavePointName(): string
return 'DOCTRINE2_SAVEPOINT_' . $this->transactionNestingLevel;
}

/**
* @throws Exception
*/
/** @throws Exception */
public function beginTransaction(): void
{
$connection = $this->connect();
Expand All @@ -1070,9 +1068,7 @@ public function beginTransaction(): void
$this->getEventManager()->dispatchEvent(Events::onTransactionBegin, new TransactionBeginEventArgs($this));
}

/**
* @throws Exception
*/
/** @throws Exception */
public function commit(): void
{
if ($this->transactionNestingLevel === 0) {
Expand Down Expand Up @@ -1126,9 +1122,7 @@ private function commitAll(): void
}
}

/**
* @throws Exception
*/
/** @throws Exception */
public function rollBack(): void
{
if ($this->transactionNestingLevel === 0) {
Expand Down Expand Up @@ -1388,14 +1382,12 @@ final public function convertExceptionDuringQuery(
Driver\Exception $e,
string $sql,
array $params = [],
array $types = []
array $types = [],
): DriverException {
return $this->handleDriverException($e, new Query($sql, $params, $types));
}

/**
* @internal
*/
/** @internal */
final public function convertException(Driver\Exception $e): DriverException
{
return $this->handleDriverException($e, null);
Expand Down Expand Up @@ -1447,7 +1439,7 @@ private function expandArrayParameters(string $sql, array $params, array $types)

private function handleDriverException(
Driver\Exception $driverException,
?Query $query
?Query $query,
): DriverException {
$this->exceptionConverter ??= $this->driver->getExceptionConverter();
$exception = $this->exceptionConverter->convert($driverException, $query);
Expand Down
4 changes: 1 addition & 3 deletions src/ConnectionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Doctrine\DBAL;

/**
* @psalm-immutable
*/
/** @psalm-immutable */
class ConnectionException extends Exception
{
}
4 changes: 2 additions & 2 deletions src/Connections/PrimaryReadReplicaConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function __construct(
array $params,
Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
?EventManager $eventManager = null,
) {
if (! isset($params['replica'], $params['primary'])) {
throw new InvalidArgumentException('primary or replica configuration missing');
Expand Down Expand Up @@ -142,7 +142,7 @@ public function connect(?string $connectionName = null): DriverConnection
if ($connectionName !== null) {
throw new InvalidArgumentException(
'Passing a connection name as first argument is not supported anymore.'
. ' Use ensureConnectedToPrimary()/ensureConnectedToReplica() instead.'
. ' Use ensureConnectedToPrimary()/ensureConnectedToReplica() instead.',
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Driver/API/MySQL/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\Query;

/**
* @internal
*/
/** @internal */
final class ExceptionConverter implements ExceptionConverterInterface
{
/**
Expand Down
8 changes: 2 additions & 6 deletions src/Driver/API/OCI/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\Query;

/**
* @internal
*/
/** @internal */
final class ExceptionConverter implements ExceptionConverterInterface
{
/**
* @link http://www.dba-oracle.com/t_error_code_list.htm
*/
/** @link http://www.dba-oracle.com/t_error_code_list.htm */
public function convert(Exception $exception, ?Query $query): DriverException
{
return match ($exception->getCode()) {
Expand Down
8 changes: 2 additions & 6 deletions src/Driver/API/PostgreSQL/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@

use function str_contains;

/**
* @internal
*/
/** @internal */
final class ExceptionConverter implements ExceptionConverterInterface
{
/**
* @link http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html
*/
/** @link http://www.postgresql.org/docs/9.4/static/errcodes-appendix.html */
public function convert(Exception $exception, ?Query $query): DriverException
{
switch ($exception->getSQLState()) {
Expand Down
8 changes: 2 additions & 6 deletions src/Driver/API/SQLite/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,10 @@

use function str_contains;

/**
* @internal
*/
/** @internal */
final class ExceptionConverter implements ExceptionConverterInterface
{
/**
* @link http://www.sqlite.org/c3ref/c_abort.html
*/
/** @link http://www.sqlite.org/c3ref/c_abort.html */
public function convert(Exception $exception, ?Query $query): DriverException
{
if (str_contains($exception->getMessage(), 'database is locked')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/AbstractException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(
string $message,
private readonly ?string $sqlState = null,
int $code = 0,
?Throwable $previous = null
?Throwable $previous = null,
) {
parent::__construct($message, $code, $previous);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/AbstractMySQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ private function getOracleMysqlVersionNumber(string $versionString): string
preg_match(
'/^(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>\d+))?)?/',
$versionString,
$versionParts
$versionParts,
) === 0
) {
throw InvalidPlatformVersion::new(
$versionString,
'<major_version>.<minor_version>.<patch_version>'
'<major_version>.<minor_version>.<patch_version>',
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Driver/AbstractOracleDriver/EasyConnectString.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ public static function fromConnectionParameters(array $params): self
]);
}

/**
* @param mixed[] $params
*/
/** @param mixed[] $params */
private static function renderParams(array $params): string
{
$chunks = [];
Expand Down
Loading

0 comments on commit 4bb2c0b

Please sign in to comment.