From 1739071598b17fd1ebcb292feab0a7a82ea403c2 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 24 Jun 2021 18:05:53 -0700 Subject: [PATCH 1/3] Configure PHP version for PHP_CodeSniffer --- .github/workflows/coding-standards.yml | 2 +- phpcs.xml.dist | 9 ++------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index a5720420006..65c92570643 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" steps: - name: "Checkout" diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 43d3af6fe7f..3374e1f07b5 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -12,6 +12,8 @@ + + bin lib tests/Doctrine/Tests @@ -37,13 +39,6 @@ */lib/Doctrine/DBAL/Driver/PDOStatementImplementations.php - - - - - - - */lib/Doctrine/DBAL/Configuration.php */lib/Doctrine/DBAL/Connection.php From 794f71e9f9a88a65ff03c03ac32d021ea8a8c48a Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 2 Jul 2021 08:56:26 -0700 Subject: [PATCH 2/3] Update Psalm to 4.8.1 --- composer.json | 2 +- .../Connections/PrimaryReadReplicaConnection.php | 8 ++++---- lib/Doctrine/DBAL/Platforms/AbstractPlatform.php | 10 +++++----- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 8 ++++---- lib/Doctrine/DBAL/Platforms/OraclePlatform.php | 4 ++-- lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php | 12 ++++++------ .../Connection/BackwardCompatibility/Connection.php | 4 ++-- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index af0f595948a..fe0f3411a99 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "squizlabs/php_codesniffer": "3.6.0", "symfony/cache": "^4.4", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", - "vimeo/psalm": "4.6.4" + "vimeo/psalm": "4.8.1" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." diff --git a/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php index 2a1fa39dd3c..e2606e7d296 100644 --- a/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php +++ b/lib/Doctrine/DBAL/Connections/PrimaryReadReplicaConnection.php @@ -367,11 +367,11 @@ public function insert($table, array $data, array $types = []) /** * {@inheritDoc} */ - public function exec($statement) + public function exec($sql) { $this->ensureConnectedToPrimary(); - return parent::exec($statement); + return parent::exec($sql); } /** @@ -433,10 +433,10 @@ public function query() /** * {@inheritDoc} */ - public function prepare($statement) + public function prepare($sql) { $this->ensureConnectedToPrimary(); - return parent::prepare($statement); + return parent::prepare($sql); } } diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 7e58d5f351b..9274e1bfdb4 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -1411,13 +1411,13 @@ public function getWriteLockSQL() /** * Returns the SQL snippet to drop an existing database. * - * @param string $database The name of the database that should be dropped. + * @param string $name The name of the database that should be dropped. * * @return string */ - public function getDropDatabaseSQL($database) + public function getDropDatabaseSQL($name) { - return 'DROP DATABASE ' . $database; + return 'DROP DATABASE ' . $name; } /** @@ -2990,13 +2990,13 @@ public function getSequenceNextValSQL($sequence) /** * Returns the SQL to create a new database. * - * @param string $database The name of the database that should be created. + * @param string $name The name of the database that should be created. * * @return string * * @throws Exception If not supported on this platform. */ - public function getCreateDatabaseSQL($database) + public function getCreateDatabaseSQL($name) { throw Exception::notSupported(__METHOD__); } diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index 3d75866e198..28f76ca4c6f 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -414,17 +414,17 @@ public function getDropViewSQL($name) /** * {@inheritDoc} */ - public function getCreateDatabaseSQL($database) + public function getCreateDatabaseSQL($name) { - return 'CREATE DATABASE ' . $database; + return 'CREATE DATABASE ' . $name; } /** * {@inheritDoc} */ - public function getDropDatabaseSQL($database) + public function getDropDatabaseSQL($name) { - return 'DROP DATABASE ' . $database; + return 'DROP DATABASE ' . $name; } /** diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 88b4325b7ce..46783d8bf8e 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -785,9 +785,9 @@ public function getForeignKeyReferentialActionSQL($action) /** * {@inheritDoc} */ - public function getDropDatabaseSQL($database) + public function getDropDatabaseSQL($name) { - return 'DROP USER ' . $database . ' CASCADE'; + return 'DROP USER ' . $name . ' CASCADE'; } /** diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 48a36a77692..591682ca158 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -406,11 +406,11 @@ public function getCreateConstraintSQL(Constraint $constraint, $table) /** * {@inheritdoc} */ - public function getCreateDatabaseSQL($database) + public function getCreateDatabaseSQL($name) { - $database = new Identifier($database); + $name = new Identifier($name); - return "CREATE DATABASE '" . $database->getName() . "'"; + return "CREATE DATABASE '" . $name->getName() . "'"; } /** @@ -540,11 +540,11 @@ public function getDefaultTransactionIsolationLevel() /** * {@inheritdoc} */ - public function getDropDatabaseSQL($database) + public function getDropDatabaseSQL($name) { - $database = new Identifier($database); + $name = new Identifier($name); - return "DROP DATABASE '" . $database->getName() . "'"; + return "DROP DATABASE '" . $name->getName() . "'"; } /** diff --git a/tests/Doctrine/Tests/DBAL/Functional/Connection/BackwardCompatibility/Connection.php b/tests/Doctrine/Tests/DBAL/Functional/Connection/BackwardCompatibility/Connection.php index aa0496fee89..41865c3d493 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Connection/BackwardCompatibility/Connection.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Connection/BackwardCompatibility/Connection.php @@ -26,9 +26,9 @@ public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheP /** * {@inheritdoc} */ - public function prepare($statement) + public function prepare($sql) { - return new Statement(parent::prepare($statement)); + return new Statement(parent::prepare($sql)); } /** From 0b1736e88f666e3efc30703e09aba2cb21b7cc29 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Mon, 5 Jul 2021 15:39:54 -0700 Subject: [PATCH 3/3] Replace closures with private methods where possible --- src/Portability/Converter.php | 101 ++++++++++++++++++---------------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/src/Portability/Converter.php b/src/Portability/Converter.php index a19d889d2fa..5763c26039d 100644 --- a/src/Portability/Converter.php +++ b/src/Portability/Converter.php @@ -38,29 +38,17 @@ final class Converter */ public function __construct(bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case) { - $id = - /** - * @param T $value - * - * @return T - * - * @template T - */ - static function ($value) { - return $value; - }; - $convertValue = $this->createConvertValue($convertEmptyStringToNull, $rightTrimString); $convertNumeric = $this->createConvertRow($convertValue, null); $convertAssociative = $this->createConvertRow($convertValue, $case); - $this->convertNumeric = $this->createConvert($convertNumeric, $id); - $this->convertAssociative = $this->createConvert($convertAssociative, $id); - $this->convertOne = $this->createConvert($convertValue, $id); + $this->convertNumeric = $this->createConvert($convertNumeric, [self::class, 'id']); + $this->convertAssociative = $this->createConvert($convertAssociative, [self::class, 'id']); + $this->convertOne = $this->createConvert($convertValue, [self::class, 'id']); - $this->convertAllNumeric = $this->createConvertAll($convertNumeric, $id); - $this->convertAllAssociative = $this->createConvertAll($convertAssociative, $id); - $this->convertFirstColumn = $this->createConvertAll($convertValue, $id); + $this->convertAllNumeric = $this->createConvertAll($convertNumeric, [self::class, 'id']); + $this->convertAllAssociative = $this->createConvertAll($convertAssociative, [self::class, 'id']); + $this->convertFirstColumn = $this->createConvertAll($convertValue, [self::class, 'id']); } /** @@ -123,6 +111,51 @@ public function convertFirstColumn(array $data): array return ($this->convertFirstColumn)($data); } + /** + * @param T $value + * + * @return T + * + * @template T + */ + private static function id($value) + { + return $value; + } + + /** + * @param T $value + * + * @return T|null + * + * @template T + */ + private static function convertEmptyStringToNull($value) + { + if ($value === '') { + return null; + } + + return $value; + } + + /** + * @param T $value + * + * @return T|string + * @psalm-return (T is string ? string : T) + * + * @template T + */ + private static function rightTrimString($value) + { + if (! is_string($value)) { + return $value; + } + + return rtrim($value); + } + /** * Creates a function that will convert each individual value retrieved from the database * @@ -136,39 +169,11 @@ private function createConvertValue(bool $convertEmptyStringToNull, bool $rightT $functions = []; if ($convertEmptyStringToNull) { - $functions[] = - /** - * @param T $value - * - * @return T|null - * - * @template T - */ - static function ($value) { - if ($value === '') { - return null; - } - - return $value; - }; + $functions[] = [self::class, 'convertEmptyStringToNull']; } if ($rightTrimString) { - $functions[] = - /** - * @param T $value - * - * @psalm-return (T is string ? string : T) - * - * @template T - */ - static function ($value) { - if (! is_string($value)) { - return $value; - } - - return rtrim($value); - }; + $functions[] = [self::class, 'rightTrimString']; } return $this->compose(...$functions);