From d40e94608a27492fc0b477ebf2dd17f89f9ed248 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 28 Nov 2021 02:04:21 +0100 Subject: [PATCH] Drop support for PHP 7 --- .appveyor.yml | 22 +++--- .github/workflows/continuous-integration.yml | 25 +++---- composer.json | 2 +- phpcs.xml.dist | 2 +- psalm.xml.dist | 7 -- src/Cache/ArrayResult.php | 20 ++---- src/Connection.php | 14 ++-- .../EasyConnectString.php | 5 +- src/Driver/Connection.php | 2 +- src/Driver/Exception/UnknownParameterType.php | 5 +- src/Driver/FetchUtils.php | 4 +- src/Driver/IBMDB2/Connection.php | 5 +- src/Driver/IBMDB2/Result.php | 15 +--- src/Driver/IBMDB2/Statement.php | 21 +++--- .../AbstractConnectionMiddleware.php | 5 +- .../Middleware/AbstractResultMiddleware.php | 15 +--- .../AbstractStatementMiddleware.php | 16 ++--- src/Driver/Mysqli/Connection.php | 5 +- src/Driver/Mysqli/Exception/InvalidOption.php | 5 +- src/Driver/Mysqli/Result.php | 15 +--- src/Driver/Mysqli/Statement.php | 16 ++--- src/Driver/OCI8/Connection.php | 5 +- src/Driver/OCI8/Result.php | 19 ++--- src/Driver/OCI8/Statement.php | 16 ++--- src/Driver/PDO/Connection.php | 5 +- src/Driver/PDO/Result.php | 19 ++--- src/Driver/PDO/SQLSrv/Statement.php | 16 ++--- src/Driver/PDO/Statement.php | 29 ++++---- src/Driver/Result.php | 8 +-- src/Driver/SQLSrv/Connection.php | 5 +- src/Driver/SQLSrv/Result.php | 20 ++---- src/Driver/SQLSrv/Statement.php | 16 ++--- src/Driver/Statement.php | 13 ++-- src/Exception/ColumnLengthRequired.php | 4 +- src/Exception/GetVariableType.php | 35 --------- src/Exception/InvalidPlatformType.php | 11 ++- src/ExpandArrayParameters.php | 11 +-- src/Logging/Statement.php | 16 ++--- src/Platforms/AbstractPlatform.php | 12 ++-- src/Platforms/PostgreSQLPlatform.php | 20 ++---- src/Platforms/SQLServerPlatform.php | 5 +- src/Platforms/SqlitePlatform.php | 2 +- src/Portability/Converter.php | 27 +++---- src/Portability/Result.php | 15 +--- src/Query/Expression/CompositeExpression.php | 22 ++---- src/Query/Expression/ExpressionBuilder.php | 22 +++--- src/Query/QueryBuilder.php | 71 ++++++++----------- src/Result.php | 10 +-- src/Schema/AbstractSchemaManager.php | 2 +- src/Schema/Column.php | 33 ++------- src/Schema/ForeignKeyConstraint.php | 4 +- src/Schema/Index.php | 5 +- src/Schema/PostgreSQLSchemaManager.php | 6 +- src/Schema/SqliteSchemaManager.php | 5 +- src/Schema/Table.php | 10 +-- src/Schema/UniqueConstraint.php | 5 +- src/Statement.php | 10 ++- src/Tools/Dumper.php | 20 ++---- src/Types/ArrayType.php | 10 +-- src/Types/BigIntType.php | 5 +- src/Types/BinaryType.php | 5 +- src/Types/BlobType.php | 5 +- src/Types/BooleanType.php | 10 +-- src/Types/DateImmutableType.php | 10 +-- src/Types/DateIntervalType.php | 10 +-- src/Types/DateTimeImmutableType.php | 10 +-- src/Types/DateTimeType.php | 10 +-- src/Types/DateTimeTzImmutableType.php | 10 +-- src/Types/DateTimeTzType.php | 10 +-- src/Types/DateType.php | 10 +-- src/Types/DecimalType.php | 5 +- src/Types/Exception/InvalidType.php | 9 +-- src/Types/Exception/SerializationFailed.php | 13 +--- src/Types/Exception/TypeAlreadyRegistered.php | 4 +- src/Types/Exception/TypeNotRegistered.php | 4 +- src/Types/Exception/ValueNotConvertible.php | 5 +- src/Types/FloatType.php | 5 +- src/Types/IntegerType.php | 5 +- src/Types/JsonType.php | 10 +-- src/Types/ObjectType.php | 10 +-- src/Types/SimpleArrayType.php | 7 +- src/Types/SmallIntType.php | 5 +- src/Types/TextType.php | 5 +- src/Types/TimeImmutableType.php | 10 +-- src/Types/TimeType.php | 10 +-- src/Types/Type.php | 7 +- src/Types/VarDateTimeImmutableType.php | 10 +-- src/Types/VarDateTimeType.php | 6 +- tests/ConnectionTest.php | 4 +- tests/Driver/AbstractDriverTest.php | 4 +- tests/DriverManagerTest.php | 10 +-- tests/Exception/GetVariableTypeTest.php | 43 ----------- tests/Functional/Schema/ComparatorTest.php | 4 +- .../SchemaManagerFunctionalTestCase.php | 4 +- tests/Functional/StatementTest.php | 24 +++---- tests/Functional/TypeConversionTest.php | 31 ++------ tests/Functional/Types/BinaryTest.php | 5 +- tests/Portability/ConverterTest.php | 15 ++-- tests/Portability/ResultTest.php | 6 +- tests/Schema/ComparatorTest.php | 7 +- tests/TestUtil.php | 2 +- tests/Types/BaseDateTypeTestCase.php | 4 +- tests/Types/BinaryTest.php | 4 +- tests/Types/ConversionExceptionTest.php | 16 ++--- tests/Types/DateImmutableTypeTest.php | 1 + tests/Types/DateIntervalTest.php | 4 +- tests/Types/DateTimeImmutableTypeTest.php | 1 + .../Exception/SerializationFailedTest.php | 2 +- tests/Types/TimeImmutableTypeTest.php | 1 + 109 files changed, 352 insertions(+), 855 deletions(-) delete mode 100644 src/Exception/GetVariableType.php delete mode 100644 tests/Exception/GetVariableTypeTest.php diff --git a/.appveyor.yml b/.appveyor.yml index b1ccdd16bac..884fc87bc4f 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -20,11 +20,11 @@ environment: - db: mssql driver: sqlsrv db_version: sql2017 - php: 7.4 + php: 8.0 - db: mssql driver: pdo_sqlsrv db_version: sql2017 - php: 7.4 + php: 8.0 init: - SET PATH=C:\Program Files\OpenSSL;c:\tools\php;C:\tools\composer;%PATH% @@ -58,19 +58,19 @@ install: Add-Content php.ini "`n extension=php_curl.dll" Add-Content php.ini "`n curl.cainfo=C:\tools\cacert\bundle.pem" - # Use a preview version of the extension that supports PHP 7.4 - $DLLVersion = "5.7.1preview" + # Get and install the latest stable sqlsrv DLL's + $DLLVersion = (Invoke-WebRequest "https://pecl.php.net/rest/r/sqlsrv/stable.txt").Content cd c:\tools\php\ext - $source = "https://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip" - $destination = "c:\tools\php\ext\php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip" + $source = "https://windows.php.net/downloads/pecl/releases/sqlsrv/$($DLLVersion)/php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vs16-x64.zip" + $destination = "c:\tools\php\ext\php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vs16-x64.zip" Invoke-WebRequest $source -OutFile $destination - 7z x -y php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip > $null - $source = "https://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip" - $destination = "c:\tools\php\ext\php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip" + 7z x -y php_sqlsrv-$($DLLVersion)-$($env:php)-nts-vs16-x64.zip > $null + $source = "https://windows.php.net/downloads/pecl/releases/pdo_sqlsrv/$($DLLVersion)/php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vs16-x64.zip" + $destination = "c:\tools\php\ext\php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vs16-x64.zip" Invoke-WebRequest $source -OutFile $destination - 7z x -y php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vc15-x64.zip > $null + 7z x -y php_pdo_sqlsrv-$($DLLVersion)-$($env:php)-nts-vs16-x64.zip > $null $DLLVersion = (Invoke-WebRequest "https://pecl.php.net/rest/r/pcov/stable.txt").Content - Invoke-WebRequest https://windows.php.net/downloads/pecl/releases/pcov/$($DLLVersion)/php_pcov-$($DLLVersion)-7.4-nts-vc15-$($env:platform).zip -OutFile pcov.zip + Invoke-WebRequest https://windows.php.net/downloads/pecl/releases/pcov/$($DLLVersion)/php_pcov-$($DLLVersion)-$($env:php)-nts-vs16-$($env:platform).zip -OutFile pcov.zip 7z x -y pcov.zip > $null Remove-Item c:\tools\php\* -include .zip cd c:\tools\php diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index c92de6b5fb3..4888d2aa172 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -22,14 +22,13 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.0" - "8.1" dependencies: - "highest" include: - dependencies: "lowest" - php-version: "7.4" + php-version: "8.0" steps: - name: "Checkout" @@ -70,7 +69,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.1" services: @@ -117,7 +115,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.1" services: @@ -164,7 +161,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" postgres-version: - "9.4" - "13" @@ -222,7 +219,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" mariadb-version: - "10.0" - "10.2" @@ -289,7 +286,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.0" mysql-version: - "5.7" @@ -300,12 +296,12 @@ jobs: config-file-suffix: - "" include: - - php-version: "7.4" + - php-version: "8.0" mysql-version: "8.0" extension: "mysqli" custom-entrypoint: >- --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - - php-version: "7.4" + - php-version: "8.0" mysql-version: "8.0" extension: "pdo_mysql" custom-entrypoint: >- @@ -316,7 +312,7 @@ jobs: custom-entrypoint: >- --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - config-file-suffix: "-tls" - php-version: "7.4" + php-version: "8.0" mysql-version: "8.0" extension: "mysqli" - php-version: "8.1" @@ -385,7 +381,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.1" extension: - "sqlsrv" @@ -394,10 +389,10 @@ jobs: - "Latin1_General_100_CI_AS_SC_UTF8" include: - collation: "Latin1_General_100_CS_AS_SC_UTF8" - php-version: "7.4" + php-version: "8.0" extension: "sqlsrv" - collation: "Latin1_General_100_CS_AS_SC_UTF8" - php-version: "7.4" + php-version: "8.0" extension: "pdo_sqlsrv" services: @@ -453,7 +448,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" services: ibm_db2: @@ -513,7 +508,7 @@ jobs: strategy: matrix: php-version: - - "7.4" + - "8.0" steps: - name: "Checkout" diff --git a/composer.json b/composer.json index 42ce44f4559..ba943755b4f 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "composer/package-versions-deprecated": "^1.11.99", "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0", diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 62b373d3e18..d1e98768778 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -12,7 +12,7 @@ - + bin src diff --git a/psalm.xml.dist b/psalm.xml.dist index fda20348ad0..48f00adf6b0 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -190,13 +190,6 @@ - - - - - - - diff --git a/src/Cache/ArrayResult.php b/src/Cache/ArrayResult.php index a2166aea157..f563b1d1748 100644 --- a/src/Cache/ArrayResult.php +++ b/src/Cache/ArrayResult.php @@ -36,10 +36,7 @@ public function __construct(array $data) $this->columnCount = count($data[0]); } - /** - * {@inheritdoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { $row = $this->fetch(); @@ -50,18 +47,12 @@ public function fetchNumeric() return array_values($row); } - /** - * {@inheritdoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { return $this->fetch(); } - /** - * {@inheritdoc} - */ - public function fetchOne() + public function fetchOne(): mixed { $row = $this->fetch(); @@ -111,10 +102,7 @@ public function free(): void $this->data = []; } - /** - * @return mixed|false - */ - private function fetch() + private function fetch(): mixed { if (! isset($this->data[$this->num])) { return false; diff --git a/src/Connection.php b/src/Connection.php index 6d7705b7370..6e606eb4532 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -387,7 +387,7 @@ public function setAutoCommit(bool $autoCommit): void * * @throws Exception */ - public function fetchAssociative(string $query, array $params = [], array $types = []) + public function fetchAssociative(string $query, array $params = [], array $types = []): array|false { return $this->executeQuery($query, $params, $types)->fetchAssociative(); } @@ -419,7 +419,7 @@ public function fetchNumeric(string $query, array $params = [], array $types = [ * * @throws Exception */ - public function fetchOne(string $query, array $params = [], array $types = []) + public function fetchOne(string $query, array $params = [], array $types = []): mixed { return $this->executeQuery($query, $params, $types)->fetchOne(); } @@ -994,7 +994,7 @@ public function getTransactionNestingLevel(): int * * @throws Exception */ - public function lastInsertId() + public function lastInsertId(): int|string { try { return $this->connect()->lastInsertId(); @@ -1017,7 +1017,7 @@ public function lastInsertId() * * @throws Throwable */ - public function transactional(Closure $func) + public function transactional(Closure $func): mixed { $this->beginTransaction(); try { @@ -1300,7 +1300,7 @@ public function isRollbackOnly(): bool * * @throws Exception */ - public function convertToDatabaseValue($value, string $type) + public function convertToDatabaseValue(mixed $value, string $type): mixed { return Type::getType($type)->convertToDatabaseValue($value, $this->getDatabasePlatform()); } @@ -1316,7 +1316,7 @@ public function convertToDatabaseValue($value, string $type) * * @throws Exception */ - public function convertToPHPValue($value, string $type) + public function convertToPHPValue(mixed $value, string $type): mixed { return Type::getType($type)->convertToPHPValue($value, $this->getDatabasePlatform()); } @@ -1372,7 +1372,7 @@ private function _bindTypedValues(DriverStatement $stmt, array $params, array $t * * @throws Exception */ - private function getBindingInfo($value, $type): array + private function getBindingInfo(mixed $value, int|string|Type|null $type): array { if (is_string($type)) { $type = Type::getType($type); diff --git a/src/Driver/AbstractOracleDriver/EasyConnectString.php b/src/Driver/AbstractOracleDriver/EasyConnectString.php index 1ea6226bbff..b7bad7e2d4b 100644 --- a/src/Driver/AbstractOracleDriver/EasyConnectString.php +++ b/src/Driver/AbstractOracleDriver/EasyConnectString.php @@ -106,10 +106,7 @@ private static function renderParams(array $params): string return implode('', $chunks); } - /** - * @param mixed $value - */ - private static function renderValue($value): string + private static function renderValue(mixed $value): string { if (is_array($value)) { return self::renderParams($value); diff --git a/src/Driver/Connection.php b/src/Driver/Connection.php index f3f083c42c0..5cb288f72f4 100644 --- a/src/Driver/Connection.php +++ b/src/Driver/Connection.php @@ -59,7 +59,7 @@ public function exec(string $sql): int; * * @throws Exception */ - public function lastInsertId(); + public function lastInsertId(): int|string; /** * Initiates a transaction. diff --git a/src/Driver/Exception/UnknownParameterType.php b/src/Driver/Exception/UnknownParameterType.php index c989184d6b6..49cf6c9d702 100644 --- a/src/Driver/Exception/UnknownParameterType.php +++ b/src/Driver/Exception/UnknownParameterType.php @@ -15,10 +15,7 @@ */ final class UnknownParameterType extends AbstractException { - /** - * @param mixed $type - */ - public static function new($type): self + public static function new(int $type): self { return new self(sprintf('Unknown parameter type, %d given.', $type)); } diff --git a/src/Driver/FetchUtils.php b/src/Driver/FetchUtils.php index 240cef4a001..65bc9e1b551 100644 --- a/src/Driver/FetchUtils.php +++ b/src/Driver/FetchUtils.php @@ -10,11 +10,9 @@ final class FetchUtils { /** - * @return mixed|false - * * @throws Exception */ - public static function fetchOne(Result $result) + public static function fetchOne(Result $result): mixed { $row = $result->fetchNumeric(); diff --git a/src/Driver/IBMDB2/Connection.php b/src/Driver/IBMDB2/Connection.php index c24b47bd967..38fe14a12f0 100644 --- a/src/Driver/IBMDB2/Connection.php +++ b/src/Driver/IBMDB2/Connection.php @@ -81,10 +81,7 @@ public function exec(string $sql): int return db2_num_rows($stmt); } - /** - * {@inheritDoc} - */ - public function lastInsertId() + public function lastInsertId(): int|string { $lastInsertId = db2_last_insert_id($this->connection); diff --git a/src/Driver/IBMDB2/Result.php b/src/Driver/IBMDB2/Result.php index d8e9fc599bc..4976fd83875 100644 --- a/src/Driver/IBMDB2/Result.php +++ b/src/Driver/IBMDB2/Result.php @@ -30,10 +30,7 @@ public function __construct($statement) $this->statement = $statement; } - /** - * {@inheritDoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { $row = @db2_fetch_array($this->statement); @@ -44,10 +41,7 @@ public function fetchNumeric() return $row; } - /** - * {@inheritDoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { $row = @db2_fetch_assoc($this->statement); @@ -58,10 +52,7 @@ public function fetchAssociative() return $row; } - /** - * {@inheritDoc} - */ - public function fetchOne() + public function fetchOne(): mixed { return FetchUtils::fetchOne($this); } diff --git a/src/Driver/IBMDB2/Statement.php b/src/Driver/IBMDB2/Statement.php index 8d106281e8c..d31ef1ea4d1 100644 --- a/src/Driver/IBMDB2/Statement.php +++ b/src/Driver/IBMDB2/Statement.php @@ -57,21 +57,19 @@ public function __construct($stmt) $this->stmt = $stmt; } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { assert(is_int($param)); $this->bindParam($param, $value, $type); } - /** - * {@inheritdoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { assert(is_int($param)); switch ($type) { @@ -100,12 +98,9 @@ public function bindParam($param, &$variable, int $type = ParameterType::STRING, } /** - * @param int $position Parameter position - * @param mixed $variable - * * @throws Exception */ - private function bind(int $position, &$variable, int $parameterType, int $dataType): void + private function bind(int $position, mixed &$variable, int $parameterType, int $dataType): void { $this->bindParam[$position] =& $variable; diff --git a/src/Driver/Middleware/AbstractConnectionMiddleware.php b/src/Driver/Middleware/AbstractConnectionMiddleware.php index 548bd968648..2955bc03ba0 100644 --- a/src/Driver/Middleware/AbstractConnectionMiddleware.php +++ b/src/Driver/Middleware/AbstractConnectionMiddleware.php @@ -37,10 +37,7 @@ public function exec(string $sql): int return $this->wrappedConnection->exec($sql); } - /** - * {@inheritdoc} - */ - public function lastInsertId() + public function lastInsertId(): int|string { return $this->wrappedConnection->lastInsertId(); } diff --git a/src/Driver/Middleware/AbstractResultMiddleware.php b/src/Driver/Middleware/AbstractResultMiddleware.php index 04cd2e8a48b..d1224756e3b 100644 --- a/src/Driver/Middleware/AbstractResultMiddleware.php +++ b/src/Driver/Middleware/AbstractResultMiddleware.php @@ -15,26 +15,17 @@ public function __construct(Result $result) $this->wrappedResult = $result; } - /** - * {@inheritdoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { return $this->wrappedResult->fetchNumeric(); } - /** - * {@inheritdoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { return $this->wrappedResult->fetchAssociative(); } - /** - * {@inheritdoc} - */ - public function fetchOne() + public function fetchOne(): mixed { return $this->wrappedResult->fetchOne(); } diff --git a/src/Driver/Middleware/AbstractStatementMiddleware.php b/src/Driver/Middleware/AbstractStatementMiddleware.php index d5580129d0e..db604e9296f 100644 --- a/src/Driver/Middleware/AbstractStatementMiddleware.php +++ b/src/Driver/Middleware/AbstractStatementMiddleware.php @@ -17,19 +17,17 @@ public function __construct(Statement $wrappedStatement) $this->wrappedStatement = $wrappedStatement; } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { $this->wrappedStatement->bindValue($param, $value, $type); } - /** - * {@inheritdoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { $this->wrappedStatement->bindParam($param, $variable, $type, $length); } diff --git a/src/Driver/Mysqli/Connection.php b/src/Driver/Mysqli/Connection.php index d29dcf4e8ed..885b08098a3 100644 --- a/src/Driver/Mysqli/Connection.php +++ b/src/Driver/Mysqli/Connection.php @@ -92,10 +92,7 @@ public function exec(string $sql): int return $this->connection->affected_rows; } - /** - * {@inheritDoc} - */ - public function lastInsertId() + public function lastInsertId(): int|string { $lastInsertId = $this->connection->insert_id; diff --git a/src/Driver/Mysqli/Exception/InvalidOption.php b/src/Driver/Mysqli/Exception/InvalidOption.php index 962175679c2..1e0482c3109 100644 --- a/src/Driver/Mysqli/Exception/InvalidOption.php +++ b/src/Driver/Mysqli/Exception/InvalidOption.php @@ -15,10 +15,7 @@ */ final class InvalidOption extends AbstractException { - /** - * @param mixed $value - */ - public static function fromOption(int $option, $value): self + public static function fromOption(int $option, mixed $value): self { return new self( sprintf('Failed to set option %d with value "%s"', $option, $value) diff --git a/src/Driver/Mysqli/Result.php b/src/Driver/Mysqli/Result.php index c096e6d7624..e7845e191b0 100644 --- a/src/Driver/Mysqli/Result.php +++ b/src/Driver/Mysqli/Result.php @@ -84,10 +84,7 @@ public function __construct(mysqli_stmt $statement) } } - /** - * {@inheritdoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { try { $ret = $this->statement->fetch(); @@ -112,10 +109,7 @@ public function fetchNumeric() return $values; } - /** - * {@inheritDoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { $values = $this->fetchNumeric(); @@ -126,10 +120,7 @@ public function fetchAssociative() return array_combine($this->columnNames, $values); } - /** - * {@inheritdoc} - */ - public function fetchOne() + public function fetchOne(): mixed { return FetchUtils::fetchOne($this); } diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index ef0878f21bd..cfbbfa0a3f6 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -63,11 +63,12 @@ public function __construct(mysqli_stmt $stmt) $this->boundValues = array_fill(1, $paramCount, null); } - /** - * {@inheritdoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { assert(is_int($param)); if (! isset(self::$paramTypeMap[$type])) { @@ -78,10 +79,7 @@ public function bindParam($param, &$variable, int $type = ParameterType::STRING, $this->types[$param - 1] = self::$paramTypeMap[$type]; } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { assert(is_int($param)); diff --git a/src/Driver/OCI8/Connection.php b/src/Driver/OCI8/Connection.php index 2d4b06ee31c..1db45c5a0b8 100644 --- a/src/Driver/OCI8/Connection.php +++ b/src/Driver/OCI8/Connection.php @@ -93,10 +93,7 @@ public function exec(string $sql): int return $this->prepare($sql)->execute()->rowCount(); } - /** - * {@inheritDoc} - */ - public function lastInsertId() + public function lastInsertId(): int|string { throw IdentityColumnsNotSupported::new(); } diff --git a/src/Driver/OCI8/Result.php b/src/Driver/OCI8/Result.php index 8f77da75905..0415cbfe25e 100644 --- a/src/Driver/OCI8/Result.php +++ b/src/Driver/OCI8/Result.php @@ -38,26 +38,17 @@ public function __construct($statement) $this->statement = $statement; } - /** - * {@inheritDoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { return $this->fetch(OCI_NUM); } - /** - * {@inheritDoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { return $this->fetch(OCI_ASSOC); } - /** - * {@inheritDoc} - */ - public function fetchOne() + public function fetchOne(): mixed { return FetchUtils::fetchOne($this); } @@ -114,11 +105,9 @@ public function free(): void } /** - * @return mixed|false - * * @throws Exception */ - private function fetch(int $mode) + private function fetch(int $mode): mixed { $result = oci_fetch_array($this->statement, $mode | OCI_RETURN_NULLS | OCI_RETURN_LOBS); diff --git a/src/Driver/OCI8/Statement.php b/src/Driver/OCI8/Statement.php index 7c079e3b83f..a3a2056abd7 100644 --- a/src/Driver/OCI8/Statement.php +++ b/src/Driver/OCI8/Statement.php @@ -50,19 +50,17 @@ public function __construct($connection, $statement, array $parameterMap, Execut $this->executionMode = $executionMode; } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { $this->bindParam($param, $value, $type); } - /** - * {@inheritdoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { if (is_int($param)) { if (! isset($this->parameterMap[$param])) { throw UnknownParameterIndex::new($param); diff --git a/src/Driver/PDO/Connection.php b/src/Driver/PDO/Connection.php index b1a7f4ea703..b1b4745b73c 100644 --- a/src/Driver/PDO/Connection.php +++ b/src/Driver/PDO/Connection.php @@ -74,10 +74,7 @@ public function quote(string $value): string return $this->connection->quote($value); } - /** - * {@inheritDoc} - */ - public function lastInsertId() + public function lastInsertId(): int|string { try { $value = $this->connection->lastInsertId(); diff --git a/src/Driver/PDO/Result.php b/src/Driver/PDO/Result.php index 3d34cfb26b3..b73e2184327 100644 --- a/src/Driver/PDO/Result.php +++ b/src/Driver/PDO/Result.php @@ -24,26 +24,17 @@ public function __construct(PDOStatement $statement) $this->statement = $statement; } - /** - * {@inheritDoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { return $this->fetch(PDO::FETCH_NUM); } - /** - * {@inheritDoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { return $this->fetch(PDO::FETCH_ASSOC); } - /** - * {@inheritDoc} - */ - public function fetchOne() + public function fetchOne(): mixed { return $this->fetch(PDO::FETCH_COLUMN); } @@ -96,11 +87,9 @@ public function free(): void } /** - * @return mixed|false - * * @throws Exception */ - private function fetch(int $mode) + private function fetch(int $mode): mixed { try { return $this->statement->fetch($mode); diff --git a/src/Driver/PDO/SQLSrv/Statement.php b/src/Driver/PDO/SQLSrv/Statement.php index a205b161966..ccccd56e2e8 100644 --- a/src/Driver/PDO/SQLSrv/Statement.php +++ b/src/Driver/PDO/SQLSrv/Statement.php @@ -23,11 +23,12 @@ public function __construct(PDOStatement $statement) $this->statement = $statement; } - /** - * {@inheritdoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { switch ($type) { case ParameterType::LARGE_OBJECT: case ParameterType::BINARY: @@ -55,10 +56,7 @@ public function bindParam($param, &$variable, int $type = ParameterType::STRING, } } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { $this->bindParam($param, $value, $type); } diff --git a/src/Driver/PDO/Statement.php b/src/Driver/PDO/Statement.php index 35d4685bdce..8b86b72df1d 100644 --- a/src/Driver/PDO/Statement.php +++ b/src/Driver/PDO/Statement.php @@ -34,10 +34,7 @@ public function __construct(PDOStatement $stmt) $this->stmt = $stmt; } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { $type = $this->convertParamType($type); @@ -48,11 +45,12 @@ public function bindValue($param, $value, int $type = ParameterType::STRING): vo } } - /** - * {@inheritDoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + string|int $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { try { if ($length === null) { $this->stmt->bindParam($param, $variable, $this->convertParamType($type)); @@ -67,14 +65,15 @@ public function bindParam($param, &$variable, int $type = ParameterType::STRING, /** * @internal Driver options can be only specified by a PDO-based driver. * - * @param string|int $param - * @param mixed $variable - * @param mixed $driverOptions - * * @throws ExceptionInterface */ - public function bindParamWithDriverOptions($param, &$variable, int $type, int $length, $driverOptions): void - { + public function bindParamWithDriverOptions( + string|int $param, + mixed &$variable, + int $type, + int $length, + mixed $driverOptions + ): void { try { $this->stmt->bindParam($param, $variable, $this->convertParamType($type), $length, $driverOptions); } catch (PDOException $exception) { diff --git a/src/Driver/Result.php b/src/Driver/Result.php index 7843a95891b..3d946108025 100644 --- a/src/Driver/Result.php +++ b/src/Driver/Result.php @@ -16,7 +16,7 @@ interface Result * * @throws Exception */ - public function fetchNumeric(); + public function fetchNumeric(): array|false; /** * Returns the next row of the result as an associative array or FALSE if there are no more rows. @@ -25,16 +25,14 @@ public function fetchNumeric(); * * @throws Exception */ - public function fetchAssociative(); + public function fetchAssociative(): array|false; /** * Returns the first value of the next row of the result or FALSE if there are no more rows. * - * @return mixed|false - * * @throws Exception */ - public function fetchOne(); + public function fetchOne(): mixed; /** * Returns an array containing all of the result rows represented as numeric arrays. diff --git a/src/Driver/SQLSrv/Connection.php b/src/Driver/SQLSrv/Connection.php index f7b7efb916f..e43adef3713 100644 --- a/src/Driver/SQLSrv/Connection.php +++ b/src/Driver/SQLSrv/Connection.php @@ -70,10 +70,7 @@ public function exec(string $sql): int return $rowsAffected; } - /** - * {@inheritDoc} - */ - public function lastInsertId() + public function lastInsertId(): int|string { $result = $this->query('SELECT @@IDENTITY'); diff --git a/src/Driver/SQLSrv/Result.php b/src/Driver/SQLSrv/Result.php index 0e24002cc26..2d77545af9b 100644 --- a/src/Driver/SQLSrv/Result.php +++ b/src/Driver/SQLSrv/Result.php @@ -30,26 +30,17 @@ public function __construct($stmt) $this->statement = $stmt; } - /** - * {@inheritDoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { return $this->fetch(SQLSRV_FETCH_NUMERIC); } - /** - * {@inheritDoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { return $this->fetch(SQLSRV_FETCH_ASSOC); } - /** - * {@inheritDoc} - */ - public function fetchOne() + public function fetchOne(): mixed { return FetchUtils::fetchOne($this); } @@ -110,10 +101,7 @@ public function free(): void } } - /** - * @return mixed|false - */ - private function fetch(int $fetchType) + private function fetch(int $fetchType): mixed { return sqlsrv_fetch_array($this->statement, $fetchType) ?? false; } diff --git a/src/Driver/SQLSrv/Statement.php b/src/Driver/SQLSrv/Statement.php index 8f0aafb2485..f28447d252a 100644 --- a/src/Driver/SQLSrv/Statement.php +++ b/src/Driver/SQLSrv/Statement.php @@ -79,10 +79,7 @@ public function __construct($conn, string $sql) $this->sql .= self::LAST_INSERT_ID_SQL; } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { assert(is_int($param)); @@ -90,11 +87,12 @@ public function bindValue($param, $value, int $type = ParameterType::STRING): vo $this->types[$param] = $type; } - /** - * {@inheritdoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { assert(is_int($param)); $this->variables[$param] =& $variable; diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index 64cb12be05d..1f68b9ba78e 100644 --- a/src/Driver/Statement.php +++ b/src/Driver/Statement.php @@ -18,7 +18,7 @@ interface Statement * As mentioned above, the named parameters are not natively supported by the mysqli driver, use executeQuery(), * fetchAll(), fetchArray(), fetchColumn(), fetchAssoc() methods to have the named parameter emulated by doctrine. * - * @param string|int $param Parameter identifier. For a prepared statement using named placeholders, + * @param int|string $param Parameter identifier. For a prepared statement using named placeholders, * this will be a parameter name of the form :name. For a prepared statement * using question mark placeholders, this will be the 1-indexed position of the parameter. * @param mixed $value The value to bind to the parameter. @@ -27,7 +27,7 @@ interface Statement * * @throws Exception */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void; + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void; /** * Binds a PHP variable to a corresponding named (not supported by mysqli driver, see comment below) or question @@ -43,7 +43,7 @@ public function bindValue($param, $value, int $type = ParameterType::STRING): vo * of stored procedures that return data as output parameters, and some also as input/output * parameters that both send in data and are updated to receive it. * - * @param string|int $param Parameter identifier. For a prepared statement using named placeholders, + * @param int|string $param Parameter identifier. For a prepared statement using named placeholders, * this will be a parameter name of the form :name. For a prepared statement using * question mark placeholders, this will be the 1-indexed position of the parameter. * @param mixed $variable The variable to bind to the parameter. @@ -54,7 +54,12 @@ public function bindValue($param, $value, int $type = ParameterType::STRING): vo * * @throws Exception */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void; + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void; /** * Executes a prepared statement diff --git a/src/Exception/ColumnLengthRequired.php b/src/Exception/ColumnLengthRequired.php index ccb09eab759..f7e02233a55 100644 --- a/src/Exception/ColumnLengthRequired.php +++ b/src/Exception/ColumnLengthRequired.php @@ -7,7 +7,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; -use function get_class; +use function get_debug_type; use function sprintf; /** @@ -24,7 +24,7 @@ public static function new(AbstractPlatform $platform, string $type): self return new self( sprintf( '%s requires the length of a %s column to be specified', - get_class($platform), + get_debug_type($platform), $type ) ); diff --git a/src/Exception/GetVariableType.php b/src/Exception/GetVariableType.php deleted file mode 100644 index 5069206ec03..00000000000 --- a/src/Exception/GetVariableType.php +++ /dev/null @@ -1,35 +0,0 @@ -__invoke($invalidPlatform) + get_debug_type($invalidPlatform) ) ); } diff --git a/src/ExpandArrayParameters.php b/src/ExpandArrayParameters.php index aad482ee132..791b9810076 100644 --- a/src/ExpandArrayParameters.php +++ b/src/ExpandArrayParameters.php @@ -86,11 +86,7 @@ public function getParameters(): array return $this->convertedParameteres; } - /** - * @param int|string $key - * @param mixed $value - */ - private function acceptParameter($key, $value): void + private function acceptParameter(int|string $key, mixed $value): void { if (! isset($this->originalTypes[$key])) { $this->convertedSQL[] = '?'; @@ -125,10 +121,9 @@ public function getTypes(): array } /** - * @param list $values - * @param Type|int|string|null $type + * @param list $values */ - private function appendTypedParameter(array $values, $type): void + private function appendTypedParameter(array $values, Type|int|string|null $type): void { $this->convertedSQL[] = implode(', ', array_fill(0, count($values), '?')); diff --git a/src/Logging/Statement.php b/src/Logging/Statement.php index 97b110b1fd6..b1575106c90 100644 --- a/src/Logging/Statement.php +++ b/src/Logging/Statement.php @@ -33,21 +33,19 @@ public function __construct(StatementInterface $statement, LoggerInterface $logg $this->sql = $sql; } - /** - * {@inheritdoc} - */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + int|string $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { $this->params[$param] = &$variable; $this->types[$param] = $type; parent::bindParam($param, $variable, $type, $length); } - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, int $type = ParameterType::STRING): void + public function bindValue(int|string $param, mixed $value, int $type = ParameterType::STRING): void { $this->params[$param] = $value; $this->types[$param] = $type; diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index d7e684943ef..2fef1fa8666 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -425,10 +425,8 @@ public function isCommentedDoctrineType(Type $doctrineType): bool /** * Marks this type as to be commented in ALTER TABLE and CREATE TABLE statements. - * - * @param string|Type $doctrineType */ - public function markDoctrineTypeCommented($doctrineType): void + public function markDoctrineTypeCommented(string|Type $doctrineType): void { if ($this->doctrineTypeComments === null) { $this->initializeCommentedDoctrineTypes(); @@ -1988,7 +1986,7 @@ public function prefersIdentityColumns(): bool * * @return mixed A boolean database value or an array of them. */ - public function convertBooleans($item) + public function convertBooleans(mixed $item): mixed { if (is_array($item)) { foreach ($item as $k => $value) { @@ -2009,10 +2007,8 @@ public function convertBooleans($item) * Some platforms have boolean literals that needs to be correctly converted * * The default conversion tries to convert value into bool "(bool)$item" - * - * @param mixed $item */ - public function convertFromBoolean($item): ?bool + public function convertFromBoolean(mixed $item): ?bool { if ($item === null) { return null; @@ -2031,7 +2027,7 @@ public function convertFromBoolean($item): ?bool * * @return mixed A boolean database value or an array of them. */ - public function convertBooleansToDatabaseValue($item) + public function convertBooleansToDatabaseValue(mixed $item): mixed { return $this->convertBooleans($item); } diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index e3748ef82f0..d141b18795b 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -613,11 +613,9 @@ protected function _getCreateTableSQL(string $name, array $columns, array $optio * @param mixed $value The value to convert. * @param callable $callback The callback function to use for converting the real boolean value. * - * @return mixed - * * @throws UnexpectedValueException */ - private function convertSingleBooleanValue($value, callable $callback) + private function convertSingleBooleanValue(mixed $value, callable $callback): mixed { if ($value === null) { return $callback(null); @@ -657,10 +655,8 @@ private function convertSingleBooleanValue($value, callable $callback) * * @param mixed $item The value(s) to convert. * @param callable $callback The callback function to use for converting the real boolean value(s). - * - * @return mixed */ - private function doConvertBooleans($item, callable $callback) + private function doConvertBooleans(mixed $item, callable $callback): mixed { if (is_array($item)) { foreach ($item as $key => $value) { @@ -678,7 +674,7 @@ private function doConvertBooleans($item, callable $callback) * * Postgres wants boolean values converted to the strings 'true'/'false'. */ - public function convertBooleans($item) + public function convertBooleans(mixed $item): mixed { if (! $this->useBooleanTrueFalseStrings) { return parent::convertBooleans($item); @@ -699,10 +695,7 @@ static function ($value): string { ); } - /** - * {@inheritDoc} - */ - public function convertBooleansToDatabaseValue($item) + public function convertBooleansToDatabaseValue(mixed $item): mixed { if (! $this->useBooleanTrueFalseStrings) { return parent::convertBooleansToDatabaseValue($item); @@ -719,10 +712,7 @@ static function ($value): ?int { ); } - /** - * {@inheritDoc} - */ - public function convertFromBoolean($item): ?bool + public function convertFromBoolean(mixed $item): ?bool { if (in_array($item, $this->booleanLiterals['false'], true)) { return false; diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index aa7a30bffc9..a0affa93740 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -1113,10 +1113,7 @@ protected function doModifyLimitQuery(string $query, ?int $limit, int $offset): return $query; } - /** - * {@inheritDoc} - */ - public function convertBooleans($item) + public function convertBooleans(mixed $item): mixed { if (is_array($item)) { foreach ($item as $key => $value) { diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 9d5e37fbeb6..578aa446342 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -807,7 +807,7 @@ private function replaceColumn(string $tableName, array $columns, string $column * * @throws Exception */ - private function getSimpleAlterTableSQL(TableDiff $diff) + private function getSimpleAlterTableSQL(TableDiff $diff): array|false { // Suppress changes on integer type autoincrement columns. foreach ($diff->changedColumns as $oldColumnName => $columnDiff) { diff --git a/src/Portability/Converter.php b/src/Portability/Converter.php index 5763c26039d..953b6c5dfc7 100644 --- a/src/Portability/Converter.php +++ b/src/Portability/Converter.php @@ -56,7 +56,7 @@ public function __construct(bool $convertEmptyStringToNull, bool $rightTrimStrin * * @return list|false */ - public function convertNumeric($row) + public function convertNumeric(array|false $row): array|false { return ($this->convertNumeric)($row); } @@ -66,17 +66,12 @@ public function convertNumeric($row) * * @return array|false */ - public function convertAssociative($row) + public function convertAssociative(array|false $row): array|false { return ($this->convertAssociative)($row); } - /** - * @param mixed|false $value - * - * @return mixed|false - */ - public function convertOne($value) + public function convertOne(mixed $value): mixed { return ($this->convertOne)($value); } @@ -118,7 +113,7 @@ public function convertFirstColumn(array $data): array * * @template T */ - private static function id($value) + private static function id(mixed $value): mixed { return $value; } @@ -130,7 +125,7 @@ private static function id($value) * * @template T */ - private static function convertEmptyStringToNull($value) + private static function convertEmptyStringToNull(mixed $value): mixed { if ($value === '') { return null; @@ -147,7 +142,7 @@ private static function convertEmptyStringToNull($value) * * @template T */ - private static function rightTrimString($value) + private static function rightTrimString(mixed $value): mixed { if (! is_string($value)) { return $value; @@ -224,7 +219,7 @@ private function createConvert(?callable $function, callable $id): callable * * @template T */ - static function ($value) use ($function) { + static function (mixed $value) use ($function): mixed { if ($value === false) { return false; } @@ -256,9 +251,7 @@ private function createConvertAll(?callable $function, callable $id): callable */ private function createMapper(callable $function): callable { - return static function (array $array) use ($function): array { - return array_map($function, $array); - }; + return static fn (array $array): array => array_map($function, $array); } /** @@ -284,9 +277,7 @@ private function compose(callable ...$functions): ?callable * * @template T */ - static function ($value) use ($carry, $item) { - return $item($carry($value)); - }; + static fn (mixed $value): mixed => $item($carry($value)); }); } } diff --git a/src/Portability/Result.php b/src/Portability/Result.php index a5ea91c4d2b..a7bab1b20b0 100644 --- a/src/Portability/Result.php +++ b/src/Portability/Result.php @@ -21,30 +21,21 @@ public function __construct(ResultInterface $result, Converter $converter) $this->converter = $converter; } - /** - * {@inheritDoc} - */ - public function fetchNumeric() + public function fetchNumeric(): array|false { return $this->converter->convertNumeric( parent::fetchNumeric() ); } - /** - * {@inheritDoc} - */ - public function fetchAssociative() + public function fetchAssociative(): array|false { return $this->converter->convertAssociative( parent::fetchAssociative() ); } - /** - * {@inheritDoc} - */ - public function fetchOne() + public function fetchOne(): mixed { return $this->converter->convertOne( parent::fetchOne() diff --git a/src/Query/Expression/CompositeExpression.php b/src/Query/Expression/CompositeExpression.php index 3560b3e2759..b208302aaeb 100644 --- a/src/Query/Expression/CompositeExpression.php +++ b/src/Query/Expression/CompositeExpression.php @@ -42,41 +42,27 @@ class CompositeExpression implements Countable /** * @internal Use the and() / or() factory methods. - * - * @param self|string $part - * @param self|string ...$parts */ - public function __construct(string $type, $part, ...$parts) + public function __construct(string $type, self|string $part, self|string ...$parts) { $this->type = $type; $this->parts = array_merge([$part], array_values($parts)); } - /** - * @param self|string $part - * @param self|string ...$parts - */ - public static function and($part, ...$parts): self + public static function and(self|string $part, self|string ...$parts): self { return new self(self::TYPE_AND, $part, ...$parts); } - /** - * @param self|string $part - * @param self|string ...$parts - */ - public static function or($part, ...$parts): self + public static function or(self|string $part, self|string ...$parts): self { return new self(self::TYPE_OR, $part, ...$parts); } /** * Returns a new CompositeExpression with the given parts added. - * - * @param self|string $part - * @param self|string ...$parts */ - public function with($part, ...$parts): self + public function with(self|string $part, self|string ...$parts): self { $that = clone $this; diff --git a/src/Query/Expression/ExpressionBuilder.php b/src/Query/Expression/ExpressionBuilder.php index a0b24805755..c08fa6fb7a6 100644 --- a/src/Query/Expression/ExpressionBuilder.php +++ b/src/Query/Expression/ExpressionBuilder.php @@ -38,23 +38,21 @@ public function __construct(Connection $connection) /** * Creates a conjunction of the given expressions. - * - * @param string|CompositeExpression $expression - * @param string|CompositeExpression ...$expressions */ - public function and($expression, ...$expressions): CompositeExpression - { + public function and( + string|CompositeExpression $expression, + string|CompositeExpression ...$expressions + ): CompositeExpression { return CompositeExpression::and($expression, ...$expressions); } /** * Creates a disjunction of the given expressions. - * - * @param string|CompositeExpression $expression - * @param string|CompositeExpression ...$expressions */ - public function or($expression, ...$expressions): CompositeExpression - { + public function or( + string|CompositeExpression $expression, + string|CompositeExpression ...$expressions + ): CompositeExpression { return CompositeExpression::or($expression, ...$expressions); } @@ -223,7 +221,7 @@ public function notLike(string $expression, string $pattern, ?string $escapeChar * @param string $x The SQL expression to be matched against the set. * @param string|string[] $y The SQL expression or an array of SQL expressions representing the set. */ - public function in(string $x, $y): string + public function in(string $x, string|array $y): string { return $this->comparison($x, 'IN', '(' . implode(', ', (array) $y) . ')'); } @@ -234,7 +232,7 @@ public function in(string $x, $y): string * @param string $x The SQL expression to be matched against the set. * @param string|string[] $y The SQL expression or an array of SQL expressions representing the set. */ - public function notIn(string $x, $y): string + public function notIn(string $x, string|array $y): string { return $this->comparison($x, 'NOT IN', '(' . implode(', ', (array) $y) . ')'); } diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 02f7b5647d1..6dad032004f 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -140,10 +140,8 @@ class QueryBuilder /** * The WHERE part of a SELECT, UPDATE or DELETE query. - * - * @var string|CompositeExpression|null */ - private $where; + private string|CompositeExpression|null $where = null; /** * The GROUP BY part of a SELECT query. @@ -154,10 +152,8 @@ class QueryBuilder /** * The HAVING part of a SELECT query. - * - * @var string|CompositeExpression|null */ - private $having; + private string|CompositeExpression|null $having = null; /** * The ORDER BY parts of a SELECT query. @@ -236,7 +232,7 @@ public function getState(): int * * @throws Exception */ - public function fetchAssociative() + public function fetchAssociative(): array|false { return $this->connection->fetchAssociative($this->getSQL(), $this->params, $this->paramTypes); } @@ -249,7 +245,7 @@ public function fetchAssociative() * * @throws Exception */ - public function fetchNumeric() + public function fetchNumeric(): array|false { return $this->connection->fetchNumeric($this->getSQL(), $this->params, $this->paramTypes); } @@ -262,7 +258,7 @@ public function fetchNumeric() * * @throws Exception */ - public function fetchOne() + public function fetchOne(): mixed { return $this->connection->fetchOne($this->getSQL(), $this->params, $this->paramTypes); } @@ -416,7 +412,7 @@ public function getSQL(): string * * @return $this This QueryBuilder instance. */ - public function setParameter($key, $value, $type = null): self + public function setParameter(int|string $key, mixed $value, int|string|Type|null $type = null): self { if ($type !== null) { $this->paramTypes[$key] = $type; @@ -471,7 +467,7 @@ public function getParameters(): array * * @return mixed The value of the bound parameter. */ - public function getParameter($key) + public function getParameter(string|int $key): mixed { return $this->params[$key] ?? null; } @@ -494,7 +490,7 @@ public function getParameterTypes(): array * * @return int|string|Type|null The value of the bound parameter type */ - public function getParameterType($key) + public function getParameterType(int|string $key): int|string|Type|null { return $this->paramTypes[$key] ?? null; } @@ -885,7 +881,7 @@ public function set(string $key, string $value): self * * @return $this This QueryBuilder instance. */ - public function where($predicate, ...$predicates): self + public function where(string|CompositeExpression $predicate, string|CompositeExpression ...$predicates): self { $this->where = $this->createPredicate($predicate, ...$predicates); @@ -913,7 +909,7 @@ public function where($predicate, ...$predicates): self * * @return $this This QueryBuilder instance. */ - public function andWhere($predicate, ...$predicates): self + public function andWhere(string|CompositeExpression $predicate, string|CompositeExpression ...$predicates): self { $this->where = $this->appendToPredicate( $this->where, @@ -946,7 +942,7 @@ public function andWhere($predicate, ...$predicates): self * * @return $this This QueryBuilder instance. */ - public function orWhere($predicate, ...$predicates): self + public function orWhere(string|CompositeExpression $predicate, string|CompositeExpression ...$predicates): self { $this->where = $this->appendToPredicate($this->where, CompositeExpression::TYPE_OR, $predicate, ...$predicates); @@ -1068,7 +1064,7 @@ public function values(array $values): self * * @return $this This QueryBuilder instance. */ - public function having($predicate, ...$predicates): self + public function having(string|CompositeExpression $predicate, string|CompositeExpression ...$predicates): self { $this->having = $this->createPredicate($predicate, ...$predicates); @@ -1086,7 +1082,7 @@ public function having($predicate, ...$predicates): self * * @return $this This QueryBuilder instance. */ - public function andHaving($predicate, ...$predicates): self + public function andHaving(string|CompositeExpression $predicate, string|CompositeExpression ...$predicates): self { $this->having = $this->appendToPredicate( $this->having, @@ -1109,7 +1105,7 @@ public function andHaving($predicate, ...$predicates): self * * @return $this This QueryBuilder instance. */ - public function orHaving($predicate, ...$predicates): self + public function orHaving(string|CompositeExpression $predicate, string|CompositeExpression ...$predicates): self { $this->having = $this->appendToPredicate( $this->having, @@ -1125,14 +1121,11 @@ public function orHaving($predicate, ...$predicates): self /** * Creates a CompositeExpression from one or more predicates combined by the AND logic. - * - * @param string|CompositeExpression $predicate - * @param string|CompositeExpression ...$predicates - * - * @return string|CompositeExpression */ - private function createPredicate($predicate, ...$predicates) - { + private function createPredicate( + string|CompositeExpression $predicate, + string|CompositeExpression ...$predicates + ): string|CompositeExpression { if (count($predicates) === 0) { return $predicate; } @@ -1142,14 +1135,12 @@ private function createPredicate($predicate, ...$predicates) /** * Appends the given predicates combined by the given type of logic to the current predicate. - * - * @param string|CompositeExpression|null $currentPredicate - * @param string|CompositeExpression ...$predicates - * - * @return string|CompositeExpression */ - private function appendToPredicate($currentPredicate, string $type, ...$predicates) - { + private function appendToPredicate( + string|CompositeExpression|null $currentPredicate, + string $type, + string|CompositeExpression ...$predicates + ): string|CompositeExpression { if ($currentPredicate instanceof CompositeExpression && $currentPredicate->getType() === $type) { return $currentPredicate->with(...$predicates); } @@ -1376,14 +1367,15 @@ public function __toString(): string * * @link http://www.zetacomponents.org * - * @param mixed $value - * @param int|string|Type|null $type - * @param string $placeHolder The name to bind with. The string must start with a colon ':'. + * @param string|null $placeHolder The name to bind with. The string must start with a colon ':'. * * @return string the placeholder name used. */ - public function createNamedParameter($value, $type = ParameterType::STRING, ?string $placeHolder = null): string - { + public function createNamedParameter( + mixed $value, + int|string|Type|null $type = ParameterType::STRING, + ?string $placeHolder = null + ): string { if ($placeHolder === null) { $this->boundCounter++; $placeHolder = ':dcValue' . $this->boundCounter; @@ -1410,11 +1402,8 @@ public function createNamedParameter($value, $type = ParameterType::STRING, ?str * ->where('u.username = ' . $qb->createPositionalParameter('Foo', ParameterType::STRING)) * ->orWhere('u.username = ' . $qb->createPositionalParameter('Bar', ParameterType::STRING)) * - * - * @param mixed $value - * @param int|string|Type|null $type */ - public function createPositionalParameter($value, $type = ParameterType::STRING): string + public function createPositionalParameter(mixed $value, int|string|Type|null $type = ParameterType::STRING): string { $this->setParameter($this->boundCounter, $value, $type); $this->boundCounter++; diff --git a/src/Result.php b/src/Result.php index 1d49804779d..9941139e308 100644 --- a/src/Result.php +++ b/src/Result.php @@ -51,7 +51,7 @@ public function fetchNumeric() * * @throws Exception */ - public function fetchAssociative() + public function fetchAssociative(): array|false { try { return $this->result->fetchAssociative(); @@ -63,11 +63,9 @@ public function fetchAssociative() /** * Returns the first value of the next row of the result or FALSE if there are no more rows. * - * @return mixed|false - * * @throws Exception */ - public function fetchOne() + public function fetchOne(): mixed { try { return $this->result->fetchOne(); @@ -272,11 +270,9 @@ private function ensureHasKeyValue(): void * * @deprecated This API is deprecated and will be removed after 2022 * - * @return mixed - * * @throws Exception */ - public function fetch(int $mode = FetchMode::ASSOCIATIVE) + public function fetch(int $mode = FetchMode::ASSOCIATIVE): mixed { if (func_num_args() > 1) { throw new LogicException('Only invocations with one argument are still supported by this legecy API.'); diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 6552f075dd5..9d190f77e51 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -790,7 +790,7 @@ protected function _getPortableTableForeignKeyDefinition(array $tableForeignKey) * * @throws Exception */ - protected function _execSql($sql): void + protected function _execSql(array|string $sql): void { foreach ((array) $sql as $query) { $this->_conn->executeStatement($query); diff --git a/src/Schema/Column.php b/src/Schema/Column.php index 6de66732511..6eb9606c036 100644 --- a/src/Schema/Column.php +++ b/src/Schema/Column.php @@ -29,8 +29,7 @@ class Column extends AbstractAsset protected bool $_notnull = true; - /** @var mixed */ - protected $_default; + protected mixed $_default = null; protected bool $_autoincrement = false; @@ -127,10 +126,7 @@ public function setNotnull(bool $notnull): self return $this; } - /** - * @param mixed $default - */ - public function setDefault($default): self + public function setDefault(mixed $default): self { $this->_default = $default; @@ -147,10 +143,7 @@ public function setPlatformOptions(array $platformOptions): self return $this; } - /** - * @param mixed $value - */ - public function setPlatformOption(string $name, $value): self + public function setPlatformOption(string $name, mixed $value): self { $this->_platformOptions[$name] = $value; @@ -199,10 +192,7 @@ public function getNotnull(): bool return $this->_notnull; } - /** - * @return mixed - */ - public function getDefault() + public function getDefault(): mixed { return $this->_default; } @@ -220,10 +210,7 @@ public function hasPlatformOption(string $name): bool return isset($this->_platformOptions[$name]); } - /** - * @return mixed - */ - public function getPlatformOption(string $name) + public function getPlatformOption(string $name): mixed { return $this->_platformOptions[$name]; } @@ -257,10 +244,7 @@ public function getComment(): string return $this->_comment; } - /** - * @param mixed $value - */ - public function setCustomSchemaOption(string $name, $value): self + public function setCustomSchemaOption(string $name, mixed $value): self { $this->_customSchemaOptions[$name] = $value; @@ -272,10 +256,7 @@ public function hasCustomSchemaOption(string $name): bool return isset($this->_customSchemaOptions[$name]); } - /** - * @return mixed - */ - public function getCustomSchemaOption(string $name) + public function getCustomSchemaOption(string $name): mixed { return $this->_customSchemaOptions[$name]; } diff --git a/src/Schema/ForeignKeyConstraint.php b/src/Schema/ForeignKeyConstraint.php index 1073c2f1544..aba59371293 100644 --- a/src/Schema/ForeignKeyConstraint.php +++ b/src/Schema/ForeignKeyConstraint.php @@ -223,10 +223,8 @@ public function hasOption(string $name): bool /** * Returns an option associated with the foreign key constraint. - * - * @return mixed */ - public function getOption(string $name) + public function getOption(string $name): mixed { return $this->_options[$name]; } diff --git a/src/Schema/Index.php b/src/Schema/Index.php index 4daa3418b89..b12640f7e2c 100644 --- a/src/Schema/Index.php +++ b/src/Schema/Index.php @@ -273,10 +273,7 @@ public function hasOption(string $name): bool return isset($this->options[strtolower($name)]); } - /** - * @return mixed - */ - public function getOption(string $name) + public function getOption(string $name): mixed { return $this->options[strtolower($name)]; } diff --git a/src/Schema/PostgreSQLSchemaManager.php b/src/Schema/PostgreSQLSchemaManager.php index 6014a56911e..2b2edb8fe66 100644 --- a/src/Schema/PostgreSQLSchemaManager.php +++ b/src/Schema/PostgreSQLSchemaManager.php @@ -444,12 +444,8 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column /** * PostgreSQL 9.4 puts parentheses around negative numeric default values that need to be stripped eventually. - * - * @param mixed $defaultValue - * - * @return mixed */ - private function fixVersion94NegativeNumericDefaultValue($defaultValue) + private function fixVersion94NegativeNumericDefaultValue(mixed $defaultValue): mixed { if ($defaultValue !== null && strpos($defaultValue, '(') === 0) { return trim($defaultValue, '()'); diff --git a/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php index 446849147e7..7cb42b542c0 100644 --- a/src/Schema/SqliteSchemaManager.php +++ b/src/Schema/SqliteSchemaManager.php @@ -408,10 +408,7 @@ private function getTableDiffForAlterForeignKey(Table $table): TableDiff return $tableDiff; } - /** - * @param string|Table $table - */ - private function ensureTable($table): Table + private function ensureTable(string|Table $table): Table { if (is_string($table)) { $table = $this->listTableDetails($table); diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 6f879fa665c..47695487471 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -367,10 +367,7 @@ public function addForeignKeyConstraint( return $this->_addForeignKeyConstraint($constraint); } - /** - * @param mixed $value - */ - public function addOption(string $name, $value): self + public function addOption(string $name, mixed $value): self { $this->_options[$name] = $value; @@ -608,10 +605,7 @@ public function hasOption(string $name): bool return isset($this->_options[$name]); } - /** - * @return mixed - */ - public function getOption(string $name) + public function getOption(string $name): mixed { return $this->_options[$name]; } diff --git a/src/Schema/UniqueConstraint.php b/src/Schema/UniqueConstraint.php index 362f8ca482e..d8798bbf149 100644 --- a/src/Schema/UniqueConstraint.php +++ b/src/Schema/UniqueConstraint.php @@ -131,10 +131,7 @@ public function hasOption(string $name): bool return isset($this->options[strtolower($name)]); } - /** - * @return mixed - */ - public function getOption(string $name) + public function getOption(string $name): mixed { return $this->options[strtolower($name)]; } diff --git a/src/Statement.php b/src/Statement.php index 2219eaf6888..013fa42261e 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -86,7 +86,7 @@ public function __construct(Connection $conn, Driver\Statement $statement, strin * * @throws Exception */ - public function bindValue($param, $value, $type = ParameterType::STRING): void + public function bindValue(string|int $param, mixed $value, string|int|Type $type = ParameterType::STRING): void { $this->params[$param] = $value; $this->types[$param] = $type; @@ -125,8 +125,12 @@ public function bindValue($param, $value, $type = ParameterType::STRING): void * * @throws Exception */ - public function bindParam($param, &$variable, int $type = ParameterType::STRING, ?int $length = null): void - { + public function bindParam( + string|int $param, + mixed &$variable, + int $type = ParameterType::STRING, + ?int $length = null + ): void { $this->params[$param] = $variable; $this->types[$param] = $type; diff --git a/src/Tools/Dumper.php b/src/Tools/Dumper.php index caeb0996b9d..b59817fd8e5 100644 --- a/src/Tools/Dumper.php +++ b/src/Tools/Dumper.php @@ -18,7 +18,6 @@ use function end; use function explode; use function extension_loaded; -use function get_class; use function html_entity_decode; use function ini_set; use function is_array; @@ -57,7 +56,7 @@ private function __construct() * @param mixed $var The variable to dump. * @param int $maxDepth The maximum nesting level for object properties. */ - public static function dump($var, int $maxDepth = 2): string + public static function dump(mixed $var, int $maxDepth = 2): string { $html = ini_set('html_errors', '1'); assert(is_string($html)); @@ -81,12 +80,7 @@ public static function dump($var, int $maxDepth = 2): string } } - /** - * @param mixed $var - * - * @return mixed - */ - public static function export($var, int $maxDepth) + public static function export(mixed $var, int $maxDepth): mixed { $isObj = is_object($var); @@ -95,7 +89,7 @@ public static function export($var, int $maxDepth) } if ($maxDepth === 0) { - return is_object($var) ? get_class($var) + return is_object($var) ? $var::class : (is_array($var) ? 'Array(' . count($var) . ')' : $var); } @@ -115,7 +109,7 @@ public static function export($var, int $maxDepth) $return = new stdClass(); if ($var instanceof DateTimeInterface) { - $return->__CLASS__ = get_class($var); + $return->__CLASS__ = $var::class; $return->date = $var->format('c'); $return->timezone = $var->getTimezone()->getName(); @@ -139,10 +133,8 @@ public static function export($var, int $maxDepth) /** * Fill the $return variable with class attributes * Based on obj2array function from {@see https://secure.php.net/manual/en/function.get-object-vars.php#47075} - * - * @return mixed */ - private static function fillReturnWithClassAttributes(object $var, stdClass $return, int $maxDepth) + private static function fillReturnWithClassAttributes(object $var, stdClass $return, int $maxDepth): mixed { $clone = (array) $var; @@ -161,7 +153,7 @@ private static function fillReturnWithClassAttributes(object $var, stdClass $ret private static function getClass(object $object): string { - $class = get_class($object); + $class = $object::class; if (! class_exists(Proxy::class)) { return $class; diff --git a/src/Types/ArrayType.php b/src/Types/ArrayType.php index 131750ab3f2..cf1f8e36208 100644 --- a/src/Types/ArrayType.php +++ b/src/Types/ArrayType.php @@ -27,19 +27,13 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getClobTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { // @todo 3.0 - $value === null check to save real NULL in database return serialize($value); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed { if ($value === null) { return null; diff --git a/src/Types/BigIntType.php b/src/Types/BigIntType.php index 52c344e0e97..9e6a9010065 100644 --- a/src/Types/BigIntType.php +++ b/src/Types/BigIntType.php @@ -30,10 +30,7 @@ public function getBindingType(): int return ParameterType::STRING; } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?string { return $value === null ? null : (string) $value; } diff --git a/src/Types/BinaryType.php b/src/Types/BinaryType.php index 369911937a0..7d172ac185b 100644 --- a/src/Types/BinaryType.php +++ b/src/Types/BinaryType.php @@ -25,10 +25,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getBinaryTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; diff --git a/src/Types/BlobType.php b/src/Types/BlobType.php index 9192a356274..521991822bb 100644 --- a/src/Types/BlobType.php +++ b/src/Types/BlobType.php @@ -28,10 +28,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getBlobTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed { if ($value === null) { return null; diff --git a/src/Types/BooleanType.php b/src/Types/BooleanType.php index 36e8f0ffb28..122dff1a724 100644 --- a/src/Types/BooleanType.php +++ b/src/Types/BooleanType.php @@ -20,18 +20,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getBooleanTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed { return $platform->convertBooleansToDatabaseValue($value); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?bool { return $platform->convertFromBoolean($value); } diff --git a/src/Types/DateImmutableType.php b/src/Types/DateImmutableType.php index e9ba3e11de0..8ee4e02d72c 100644 --- a/src/Types/DateImmutableType.php +++ b/src/Types/DateImmutableType.php @@ -19,10 +19,7 @@ public function getName(): string return Types::DATE_IMMUTABLE; } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -39,10 +36,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) ); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeImmutable { if ($value === null || $value instanceof DateTimeImmutable) { return $value; diff --git a/src/Types/DateIntervalType.php b/src/Types/DateIntervalType.php index aada905c63c..6a14e1a4e57 100644 --- a/src/Types/DateIntervalType.php +++ b/src/Types/DateIntervalType.php @@ -34,10 +34,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getStringTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; @@ -50,10 +47,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) throw InvalidType::new($value, $this->getName(), ['null', 'DateInterval']); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateInterval { if ($value === null || $value instanceof DateInterval) { return $value; diff --git a/src/Types/DateTimeImmutableType.php b/src/Types/DateTimeImmutableType.php index 7c4d9e0f635..36e1be5448d 100644 --- a/src/Types/DateTimeImmutableType.php +++ b/src/Types/DateTimeImmutableType.php @@ -21,10 +21,7 @@ public function getName(): string return Types::DATETIME_IMMUTABLE; } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -41,10 +38,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) ); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeImmutable { if ($value === null || $value instanceof DateTimeImmutable) { return $value; diff --git a/src/Types/DateTimeType.php b/src/Types/DateTimeType.php index c086a643a75..fbc5b85f56b 100644 --- a/src/Types/DateTimeType.php +++ b/src/Types/DateTimeType.php @@ -30,10 +30,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getDateTimeTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -46,10 +43,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface { if ($value === null || $value instanceof DateTimeInterface) { return $value; diff --git a/src/Types/DateTimeTzImmutableType.php b/src/Types/DateTimeTzImmutableType.php index b79bc9ae6c3..ebab409259c 100644 --- a/src/Types/DateTimeTzImmutableType.php +++ b/src/Types/DateTimeTzImmutableType.php @@ -19,10 +19,7 @@ public function getName(): string return Types::DATETIMETZ_IMMUTABLE; } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -39,10 +36,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) ); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeImmutable { if ($value === null || $value instanceof DateTimeImmutable) { return $value; diff --git a/src/Types/DateTimeTzType.php b/src/Types/DateTimeTzType.php index 763ffa8898c..43e9472d4a6 100644 --- a/src/Types/DateTimeTzType.php +++ b/src/Types/DateTimeTzType.php @@ -41,10 +41,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getDateTimeTzTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -61,10 +58,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) ); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface { if ($value === null || $value instanceof DateTimeInterface) { return $value; diff --git a/src/Types/DateType.php b/src/Types/DateType.php index 89e7b17a5f5..8789ddac437 100644 --- a/src/Types/DateType.php +++ b/src/Types/DateType.php @@ -28,10 +28,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getDateTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed { if ($value === null) { return $value; @@ -44,10 +41,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface { if ($value === null || $value instanceof DateTimeInterface) { return $value; diff --git a/src/Types/DecimalType.php b/src/Types/DecimalType.php index 468db2181d3..1f64d034ea4 100644 --- a/src/Types/DecimalType.php +++ b/src/Types/DecimalType.php @@ -29,10 +29,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getDecimalTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?string { // Some drivers starting from PHP 8.1 can represent decimals as float/int // See also: https://github.com/doctrine/dbal/pull/4818 diff --git a/src/Types/Exception/InvalidType.php b/src/Types/Exception/InvalidType.php index d2c2d064e19..adc89dede88 100644 --- a/src/Types/Exception/InvalidType.php +++ b/src/Types/Exception/InvalidType.php @@ -7,10 +7,8 @@ use Doctrine\DBAL\Types\ConversionException; use Throwable; -use function get_class; -use function gettype; +use function get_debug_type; use function implode; -use function is_object; use function is_scalar; use function sprintf; use function var_export; @@ -23,13 +21,12 @@ final class InvalidType extends ConversionException implements TypesException { /** - * @param mixed $value * @param string[] $possibleTypes * * @todo split into two methods * @todo sanitize value */ - public static function new($value, string $toType, array $possibleTypes, ?Throwable $previous = null): self + public static function new(mixed $value, string $toType, array $possibleTypes, ?Throwable $previous = null): self { if (is_scalar($value) || $value === null) { $message = sprintf( @@ -41,7 +38,7 @@ public static function new($value, string $toType, array $possibleTypes, ?Throwa } else { $message = sprintf( 'Could not convert PHP value of type %s to type %s. Expected one of the following types: %s.', - is_object($value) ? get_class($value) : gettype($value), + get_debug_type($value), $toType, implode(', ', $possibleTypes) ); diff --git a/src/Types/Exception/SerializationFailed.php b/src/Types/Exception/SerializationFailed.php index b6922319f56..1ba5cc6fa25 100644 --- a/src/Types/Exception/SerializationFailed.php +++ b/src/Types/Exception/SerializationFailed.php @@ -7,9 +7,7 @@ use Doctrine\DBAL\Types\ConversionException; use Throwable; -use function get_class; -use function gettype; -use function is_object; +use function get_debug_type; use function sprintf; /** @@ -17,17 +15,12 @@ */ final class SerializationFailed extends ConversionException implements TypesException { - /** - * @param mixed $value - */ - public static function new($value, string $format, string $error, ?Throwable $previous = null): self + public static function new(mixed $value, string $format, string $error, ?Throwable $previous = null): self { - $actualType = is_object($value) ? get_class($value) : gettype($value); - return new self( sprintf( 'Could not convert PHP type "%s" to "%s". An error was triggered by the serialization: %s', - $actualType, + get_debug_type($value), $format, $error ), diff --git a/src/Types/Exception/TypeAlreadyRegistered.php b/src/Types/Exception/TypeAlreadyRegistered.php index 5da825c1e9e..e530062588b 100644 --- a/src/Types/Exception/TypeAlreadyRegistered.php +++ b/src/Types/Exception/TypeAlreadyRegistered.php @@ -7,7 +7,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Types\Type; -use function get_class; +use function get_debug_type; use function spl_object_hash; use function sprintf; @@ -20,7 +20,7 @@ public static function new(Type $type): self { return new self(sprintf( 'Type of the class %s@%s is already registered.', - get_class($type), + get_debug_type($type), spl_object_hash($type) )); } diff --git a/src/Types/Exception/TypeNotRegistered.php b/src/Types/Exception/TypeNotRegistered.php index b23e5e86728..9a65d2e8615 100644 --- a/src/Types/Exception/TypeNotRegistered.php +++ b/src/Types/Exception/TypeNotRegistered.php @@ -7,7 +7,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Types\Type; -use function get_class; +use function get_debug_type; use function spl_object_hash; use function sprintf; @@ -20,7 +20,7 @@ public static function new(Type $type): self { return new self(sprintf( 'Type of the class %s@%s is not registered.', - get_class($type), + get_debug_type($type), spl_object_hash($type) )); } diff --git a/src/Types/Exception/ValueNotConvertible.php b/src/Types/Exception/ValueNotConvertible.php index 7a72b76cfa8..91fd16ee944 100644 --- a/src/Types/Exception/ValueNotConvertible.php +++ b/src/Types/Exception/ValueNotConvertible.php @@ -19,10 +19,7 @@ */ final class ValueNotConvertible extends ConversionException implements TypesException { - /** - * @param mixed $value - */ - public static function new($value, string $toType, ?string $message = null, ?Throwable $previous = null): self + public static function new(mixed $value, string $toType, ?string $message = null, ?Throwable $previous = null): self { if ($message !== null) { $message = sprintf( diff --git a/src/Types/FloatType.php b/src/Types/FloatType.php index ba341f56eb8..090c8dd7290 100644 --- a/src/Types/FloatType.php +++ b/src/Types/FloatType.php @@ -21,10 +21,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getFloatDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?float { return $value === null ? null : (float) $value; } diff --git a/src/Types/IntegerType.php b/src/Types/IntegerType.php index 9e086b9657b..ef734159d0b 100644 --- a/src/Types/IntegerType.php +++ b/src/Types/IntegerType.php @@ -25,10 +25,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getIntegerTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?int { return $value === null ? null : (int) $value; } diff --git a/src/Types/JsonType.php b/src/Types/JsonType.php index dd7fc78f1af..dc395e80377 100644 --- a/src/Types/JsonType.php +++ b/src/Types/JsonType.php @@ -29,10 +29,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getJsonTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return null; @@ -45,10 +42,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) } } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed { if ($value === null || $value === '') { return null; diff --git a/src/Types/ObjectType.php b/src/Types/ObjectType.php index c4aa413b253..da15867de6d 100644 --- a/src/Types/ObjectType.php +++ b/src/Types/ObjectType.php @@ -27,18 +27,12 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getClobTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { return serialize($value); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed { if ($value === null) { return null; diff --git a/src/Types/SimpleArrayType.php b/src/Types/SimpleArrayType.php index 53bd2b6a4a8..da0124eb664 100644 --- a/src/Types/SimpleArrayType.php +++ b/src/Types/SimpleArrayType.php @@ -28,10 +28,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getClobTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if (! is_array($value) || count($value) === 0) { return null; @@ -43,7 +40,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) /** * {@inheritdoc} */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?array { if ($value === null) { return []; diff --git a/src/Types/SmallIntType.php b/src/Types/SmallIntType.php index cdc48934a1c..1558b610247 100644 --- a/src/Types/SmallIntType.php +++ b/src/Types/SmallIntType.php @@ -25,10 +25,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getSmallIntTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?int { return $value === null ? null : (int) $value; } diff --git a/src/Types/TextType.php b/src/Types/TextType.php index f8bd92deda0..be51eef53fc 100644 --- a/src/Types/TextType.php +++ b/src/Types/TextType.php @@ -22,10 +22,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getClobTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed { return is_resource($value) ? stream_get_contents($value) : $value; } diff --git a/src/Types/TimeImmutableType.php b/src/Types/TimeImmutableType.php index bdb5be346eb..5ff685eb493 100644 --- a/src/Types/TimeImmutableType.php +++ b/src/Types/TimeImmutableType.php @@ -19,10 +19,7 @@ public function getName(): string return Types::TIME_IMMUTABLE; } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -39,10 +36,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) ); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeImmutable { if ($value === null || $value instanceof DateTimeImmutable) { return $value; diff --git a/src/Types/TimeType.php b/src/Types/TimeType.php index 9bab34ab07e..d7d53884cec 100644 --- a/src/Types/TimeType.php +++ b/src/Types/TimeType.php @@ -28,10 +28,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st return $platform->getTimeTypeDeclarationSQL($column); } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -44,10 +41,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) throw InvalidType::new($value, $this->getName(), ['null', 'DateTime']); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface { if ($value === null || $value instanceof DateTimeInterface) { return $value; diff --git a/src/Types/Type.php b/src/Types/Type.php index d564292b4b9..5c198c5abcd 100644 --- a/src/Types/Type.php +++ b/src/Types/Type.php @@ -9,7 +9,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use function array_map; -use function get_class; /** * The base class for so-called Doctrine mapping types. @@ -69,7 +68,7 @@ final public function __construct() * * @throws ConversionException */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): mixed { return $value; } @@ -85,7 +84,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) * * @throws ConversionException */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): mixed { return $value; } @@ -198,7 +197,7 @@ public static function getTypesMap(): array { return array_map( static function (Type $type): string { - return get_class($type); + return $type::class; }, self::getTypeRegistry()->getMap() ); diff --git a/src/Types/VarDateTimeImmutableType.php b/src/Types/VarDateTimeImmutableType.php index 82152c9b01f..3bccdebe500 100644 --- a/src/Types/VarDateTimeImmutableType.php +++ b/src/Types/VarDateTimeImmutableType.php @@ -21,10 +21,7 @@ public function getName(): string return Types::DATETIME_IMMUTABLE; } - /** - * {@inheritdoc} - */ - public function convertToDatabaseValue($value, AbstractPlatform $platform) + public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string { if ($value === null) { return $value; @@ -41,10 +38,7 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) ); } - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeImmutable { if ($value === null || $value instanceof DateTimeImmutable) { return $value; diff --git a/src/Types/VarDateTimeType.php b/src/Types/VarDateTimeType.php index 0da1dd5b44b..966c45a056e 100644 --- a/src/Types/VarDateTimeType.php +++ b/src/Types/VarDateTimeType.php @@ -5,6 +5,7 @@ namespace Doctrine\DBAL\Types; use DateTime; +use DateTimeInterface; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Exception\ValueNotConvertible; @@ -19,10 +20,7 @@ */ class VarDateTimeType extends DateTimeType { - /** - * {@inheritdoc} - */ - public function convertToPHPValue($value, AbstractPlatform $platform) + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?DateTimeInterface { if ($value === null || $value instanceof DateTime) { return $value; diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index c3819d870ab..00f25d2f849 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -519,11 +519,9 @@ public function testDeleteWithIsNull(): void } /** - * @param mixed $expected - * * @dataProvider fetchModeProvider */ - public function testFetch(string $method, callable $invoke, $expected): void + public function testFetch(string $method, callable $invoke, mixed $expected): void { $query = 'SELECT * FROM foo WHERE bar = ?'; $params = [666]; diff --git a/tests/Driver/AbstractDriverTest.php b/tests/Driver/AbstractDriverTest.php index 15f0d8225a5..326e0855885 100644 --- a/tests/Driver/AbstractDriverTest.php +++ b/tests/Driver/AbstractDriverTest.php @@ -15,8 +15,6 @@ use PHPUnit\Framework\TestCase; use ReflectionProperty; -use function get_class; - /** * @template P of AbstractPlatform */ @@ -41,7 +39,7 @@ public function testCreatesDatabasePlatformForVersion(string $version, string $e new StaticServerVersionProvider($version) ); - self::assertSame($expectedClass, get_class($platform)); + self::assertSame($expectedClass, $platform::class); } public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion(): void diff --git a/tests/DriverManagerTest.php b/tests/DriverManagerTest.php index ba59964d4a2..8704812ba69 100644 --- a/tests/DriverManagerTest.php +++ b/tests/DriverManagerTest.php @@ -17,7 +17,6 @@ use function array_intersect_key; use function array_merge; -use function get_class; use function in_array; use function is_array; @@ -61,7 +60,7 @@ public function testCustomPlatform(): void public function testCustomWrapper(): void { $wrapper = $this->createMock(Connection::class); - $wrapperClass = get_class($wrapper); + $wrapperClass = $wrapper::class; $options = [ 'url' => 'sqlite::memory:', @@ -152,12 +151,9 @@ public function testDatabaseUrlPrimaryReplica(): void } /** - * @param mixed $url - * @param mixed $expected - * * @dataProvider databaseUrls */ - public function testDatabaseUrl($url, $expected): void + public function testDatabaseUrl(mixed $url, mixed $expected): void { $options = is_array($url) ? $url : ['url' => $url]; @@ -183,7 +179,7 @@ public function testDatabaseUrl($url, $expected): void public function databaseUrls(): iterable { $driver = $this->createMock(Driver::class); - $driverClass = get_class($driver); + $driverClass = $driver::class; return [ 'simple URL' => [ diff --git a/tests/Exception/GetVariableTypeTest.php b/tests/Exception/GetVariableTypeTest.php deleted file mode 100644 index 9efc6dafa61..00000000000 --- a/tests/Exception/GetVariableTypeTest.php +++ /dev/null @@ -1,43 +0,0 @@ -__invoke($value)); - } - - /** - * @return array> - */ - public function provideDataForFormatVariable(): array - { - return [ - ['string', ''], - ['string', 'test'], - ['double', 1.0], - ['integer', 1], - ['NULL', null], - ['stdClass', new stdClass()], - ['stream', tmpfile()], - ['true', true], - ['false', false], - ['array', [true, 1, 2, 3, 'test']], - ]; - } -} diff --git a/tests/Functional/Schema/ComparatorTest.php b/tests/Functional/Schema/ComparatorTest.php index 6463080508c..05e4a2fb142 100644 --- a/tests/Functional/Schema/ComparatorTest.php +++ b/tests/Functional/Schema/ComparatorTest.php @@ -18,11 +18,9 @@ protected function setUp(): void } /** - * @param mixed $value - * * @dataProvider defaultValueProvider */ - public function testDefaultValueComparison(string $type, $value): void + public function testDefaultValueComparison(string $type, mixed $value): void { $table = new Table('default_value'); $table->addColumn('test', $type, ['default' => $value]); diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index e713a4184f7..d58cf9d0b3b 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -43,7 +43,7 @@ use function array_values; use function count; use function current; -use function get_class; +use function get_debug_type; use function sprintf; use function strcasecmp; use function strtolower; @@ -59,7 +59,7 @@ protected function setUp(): void $platform = $this->connection->getDatabasePlatform(); if (! $this->supportsPlatform($platform)) { - self::markTestSkipped(sprintf('Skipping since connected to %s', get_class($platform))); + self::markTestSkipped(sprintf('Skipping since connected to %s', get_debug_type($platform))); } $this->schemaManager = $this->connection->createSchemaManager(); diff --git a/tests/Functional/StatementTest.php b/tests/Functional/StatementTest.php index 1c7c55cafab..16d607d6d2c 100644 --- a/tests/Functional/StatementTest.php +++ b/tests/Functional/StatementTest.php @@ -19,7 +19,7 @@ use Error; use function base64_decode; -use function get_class; +use function get_debug_type; use function sprintf; use function stream_get_contents; @@ -237,11 +237,9 @@ public function testReuseStatementWithReboundParam(): void } /** - * @param mixed $expected - * * @dataProvider emptyFetchProvider */ - public function testFetchFromExecutedStatementWithFreedResult(callable $fetch, $expected): void + public function testFetchFromExecutedStatementWithFreedResult(callable $fetch, mixed $expected): void { $this->connection->insert('stmt_test', ['id' => 1]); @@ -271,27 +269,21 @@ public static function emptyFetchProvider(): iterable { return [ 'fetch' => [ - /** - * @return mixed - */ - static function (Result $result) { + static function (Result $result): array|false { return $result->fetchAssociative(); }, false, ], - /** - * @return mixed|false - */ 'fetch-column' => [ - static function (Result $result) { + static function (Result $result): mixed { return $result->fetchOne(); }, false, ], - /** - * @return mixed[] - */ 'fetch-all' => [ + /** + * @return mixed[] + */ static function (Result $result): array { return $result->fetchAllAssociative(); }, @@ -330,7 +322,7 @@ public function testExecWithRedundantParameters(): void ) { self::markTestSkipped(sprintf( 'The underlying implementation of the "%s" driver does not report redundant parameters', - get_class($driver) + get_debug_type($driver) )); } diff --git a/tests/Functional/TypeConversionTest.php b/tests/Functional/TypeConversionTest.php index 301e3a62520..2f40e52e756 100644 --- a/tests/Functional/TypeConversionTest.php +++ b/tests/Functional/TypeConversionTest.php @@ -44,11 +44,9 @@ protected function setUp(): void } /** - * @param mixed $originalValue - * * @dataProvider booleanProvider */ - public function testIdempotentConversionToBoolean(string $type, $originalValue): void + public function testIdempotentConversionToBoolean(string $type, mixed $originalValue): void { $dbValue = $this->processValue($type, $originalValue); @@ -68,11 +66,9 @@ public static function booleanProvider(): iterable } /** - * @param mixed $originalValue - * * @dataProvider integerProvider */ - public function testIdempotentConversionToInteger(string $type, $originalValue): void + public function testIdempotentConversionToInteger(string $type, mixed $originalValue): void { $dbValue = $this->processValue($type, $originalValue); @@ -91,11 +87,9 @@ public static function integerProvider(): iterable } /** - * @param mixed $originalValue - * * @dataProvider floatProvider */ - public function testIdempotentConversionToFloat(string $type, $originalValue): void + public function testIdempotentConversionToFloat(string $type, mixed $originalValue): void { $dbValue = $this->processValue($type, $originalValue); @@ -114,11 +108,9 @@ public static function floatProvider(): iterable } /** - * @param mixed $originalValue - * * @dataProvider toStringProvider */ - public function testIdempotentConversionToString(string $type, $originalValue): void + public function testIdempotentConversionToString(string $type, mixed $originalValue): void { if ($type === 'text' && TestUtil::isDriverOneOf('pdo_oci')) { // inserting BLOBs as streams on Oracle requires Oracle-specific SQL syntax which is currently not supported @@ -144,11 +136,9 @@ public static function toStringProvider(): iterable } /** - * @param mixed $originalValue - * * @dataProvider toArrayProvider */ - public function testIdempotentConversionToArray(string $type, $originalValue): void + public function testIdempotentConversionToArray(string $type, mixed $originalValue): void { $dbValue = $this->processValue($type, $originalValue); @@ -168,11 +158,9 @@ public static function toArrayProvider(): iterable } /** - * @param mixed $originalValue - * * @dataProvider toObjectProvider */ - public function testIdempotentConversionToObject(string $type, $originalValue): void + public function testIdempotentConversionToObject(string $type, mixed $originalValue): void { $dbValue = $this->processValue($type, $originalValue); @@ -227,12 +215,7 @@ public static function toDateTimeProvider(): iterable ]; } - /** - * @param mixed $originalValue - * - * @return mixed - */ - private function processValue(string $type, $originalValue) + private function processValue(string $type, mixed $originalValue): mixed { $columnName = 'test_' . $type; $typeInstance = Type::getType($type); diff --git a/tests/Functional/Types/BinaryTest.php b/tests/Functional/Types/BinaryTest.php index 56a7087e1f0..734af9805c8 100644 --- a/tests/Functional/Types/BinaryTest.php +++ b/tests/Functional/Types/BinaryTest.php @@ -66,10 +66,7 @@ private function insert(string $id, string $value): void self::assertSame(1, $result); } - /** - * @return mixed - */ - private function select(string $id) + private function select(string $id): mixed { $value = $this->connection->fetchOne( 'SELECT val FROM binary_table WHERE id = ?', diff --git a/tests/Portability/ConverterTest.php b/tests/Portability/ConverterTest.php index 586770e45be..f6adc053309 100644 --- a/tests/Portability/ConverterTest.php +++ b/tests/Portability/ConverterTest.php @@ -71,11 +71,11 @@ public static function convertNumericProvider(): iterable * @dataProvider convertAssociativeProvider */ public function testConvertAssociative( - $row, + array|false $row, bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case, - $expected + array|false $expected ): void { self::assertSame( $expected, @@ -186,13 +186,14 @@ public static function convertAssociativeProvider(): iterable } /** - * @param mixed|false $value - * @param mixed|false $expected - * * @dataProvider convertOneProvider */ - public function testConvertOne($value, bool $convertEmptyStringToNull, bool $rightTrimString, $expected): void - { + public function testConvertOne( + mixed $value, + bool $convertEmptyStringToNull, + bool $rightTrimString, + mixed $expected + ): void { self::assertSame( $expected, $this->createConverter($convertEmptyStringToNull, $rightTrimString, null) diff --git a/tests/Portability/ResultTest.php b/tests/Portability/ResultTest.php index 89dd123849c..0fdec58e25a 100644 --- a/tests/Portability/ResultTest.php +++ b/tests/Portability/ResultTest.php @@ -12,11 +12,9 @@ class ResultTest extends TestCase { /** - * @param mixed $return - * * @dataProvider fetchProvider */ - public function testFetch(string $source, callable $fetch, $return): void + public function testFetch(string $source, callable $fetch, mixed $return): void { $driverResult = $this->createMock(DriverResult::class); $driverResult->expects(self::once()) @@ -51,7 +49,7 @@ static function (Result $result) { yield 'one' => [ 'fetchOne', - static function (Result $result) { + static function (Result $result): mixed { return $result->fetchOne(); }, 'bar', diff --git a/tests/Schema/ComparatorTest.php b/tests/Schema/ComparatorTest.php index 399850b8ae8..ae7e8b404ce 100644 --- a/tests/Schema/ComparatorTest.php +++ b/tests/Schema/ComparatorTest.php @@ -20,7 +20,6 @@ use PHPUnit\Framework\TestCase; use function array_keys; -use function get_class; abstract class ComparatorTest extends TestCase { @@ -203,7 +202,7 @@ public function testCompareChangedColumnsChangeType(): void public function testCompareColumnsMultipleTypeInstances(): void { $integerType1 = Type::getType('integer'); - Type::overrideType('integer', get_class($integerType1)); + Type::overrideType('integer', $integerType1::class); $integerType2 = Type::getType('integer'); $column1 = new Column('integercolumn1', $integerType1); @@ -217,10 +216,10 @@ public function testCompareColumnsOverriddenType(): void $oldStringInstance = Type::getType('string'); $integerType = Type::getType('integer'); - Type::overrideType('string', get_class($integerType)); + Type::overrideType('string', $integerType::class); $overriddenStringType = Type::getType('string'); - Type::overrideType('string', get_class($oldStringInstance)); + Type::overrideType('string', $oldStringInstance::class); $column1 = new Column('integercolumn1', $integerType); $column2 = new Column('integercolumn1', $overriddenStringType); diff --git a/tests/TestUtil.php b/tests/TestUtil.php index 10a2b959040..de5bd141457 100644 --- a/tests/TestUtil.php +++ b/tests/TestUtil.php @@ -162,7 +162,7 @@ private static function addDbEventSubscribers(Connection $conn): void $evm = $conn->getEventManager(); - /** @psalm-var class-string $subscriberClass */ + /** @var class-string $subscriberClass */ foreach (explode(',', $GLOBALS['db_event_subscribers']) as $subscriberClass) { $subscriberInstance = new $subscriberClass(); $evm->addEventSubscriber($subscriberInstance); diff --git a/tests/Types/BaseDateTypeTestCase.php b/tests/Types/BaseDateTypeTestCase.php index e7af10bdaac..a880b87e7ef 100644 --- a/tests/Types/BaseDateTypeTestCase.php +++ b/tests/Types/BaseDateTypeTestCase.php @@ -42,11 +42,9 @@ public function testDateConvertsToDatabaseValue(): void } /** - * @param mixed $value - * * @dataProvider invalidPHPValuesProvider */ - public function testInvalidTypeConversionToDatabaseValue($value): void + public function testInvalidTypeConversionToDatabaseValue(mixed $value): void { $this->expectException(ConversionException::class); diff --git a/tests/Types/BinaryTest.php b/tests/Types/BinaryTest.php index b0d874ad59c..43b3cb2132d 100644 --- a/tests/Types/BinaryTest.php +++ b/tests/Types/BinaryTest.php @@ -106,11 +106,9 @@ private function getBinaryString(): string } /** - * @param mixed $value - * * @dataProvider getInvalidDatabaseValues */ - public function testThrowsConversionExceptionOnInvalidDatabaseValue($value): void + public function testThrowsConversionExceptionOnInvalidDatabaseValue(mixed $value): void { $this->expectException(ConversionException::class); diff --git a/tests/Types/ConversionExceptionTest.php b/tests/Types/ConversionExceptionTest.php index 1721c33175f..de02ad6cc26 100644 --- a/tests/Types/ConversionExceptionTest.php +++ b/tests/Types/ConversionExceptionTest.php @@ -11,9 +11,7 @@ use stdClass; use Throwable; -use function get_class; -use function gettype; -use function is_object; +use function get_debug_type; use function sprintf; use function tmpfile; @@ -29,11 +27,9 @@ public function testConversionFailedPreviousException(): void } /** - * @param mixed $scalarValue - * * @dataProvider scalarsProvider */ - public function testConversionFailedInvalidTypeWithScalar($scalarValue, string $expected): void + public function testConversionFailedInvalidTypeWithScalar(mixed $scalarValue, string $expected): void { $exception = InvalidType::new($scalarValue, 'foo', ['bar', 'baz']); @@ -44,21 +40,17 @@ public function testConversionFailedInvalidTypeWithScalar($scalarValue, string $ } /** - * @param mixed $nonScalar - * * @dataProvider nonScalarsProvider */ - public function testConversionFailedInvalidTypeWithNonScalar($nonScalar): void + public function testConversionFailedInvalidTypeWithNonScalar(mixed $nonScalar): void { $exception = InvalidType::new($nonScalar, 'foo', ['bar', 'baz']); - $type = is_object($nonScalar) ? get_class($nonScalar) : gettype($nonScalar); - self::assertSame( sprintf( 'Could not convert PHP value of type %s to type foo.' . ' Expected one of the following types: bar, baz.', - $type + get_debug_type($nonScalar) ), $exception->getMessage() ); diff --git a/tests/Types/DateImmutableTypeTest.php b/tests/Types/DateImmutableTypeTest.php index 1c28aa87d4a..644d2856bbc 100644 --- a/tests/Types/DateImmutableTypeTest.php +++ b/tests/Types/DateImmutableTypeTest.php @@ -105,6 +105,7 @@ public function testResetTimeFractionsWhenConvertingToPHPValue(): void $date = $this->type->convertToPHPValue('2016-01-01', $this->platform); + self::assertNotNull($date); self::assertSame('2016-01-01 00:00:00.000000', $date->format('Y-m-d H:i:s.u')); } diff --git a/tests/Types/DateIntervalTest.php b/tests/Types/DateIntervalTest.php index ef8b40843cc..a2dd9ae844a 100644 --- a/tests/Types/DateIntervalTest.php +++ b/tests/Types/DateIntervalTest.php @@ -95,11 +95,9 @@ public function testRequiresSQLCommentHint(): void } /** - * @param mixed $value - * * @dataProvider invalidPHPValuesProvider */ - public function testInvalidTypeConversionToDatabaseValue($value): void + public function testInvalidTypeConversionToDatabaseValue(mixed $value): void { $this->expectException(ConversionException::class); diff --git a/tests/Types/DateTimeImmutableTypeTest.php b/tests/Types/DateTimeImmutableTypeTest.php index f0c35ae2bcf..ccf9dd59ed6 100644 --- a/tests/Types/DateTimeImmutableTypeTest.php +++ b/tests/Types/DateTimeImmutableTypeTest.php @@ -105,6 +105,7 @@ public function testConvertsDateTimeStringWithMicrosecondsToPHPValue(): void $date = $this->type->convertToPHPValue('2016-01-01 15:58:59.123456', $this->platform); + self::assertNotNull($date); self::assertSame('2016-01-01 15:58:59', $date->format('Y-m-d H:i:s')); } diff --git a/tests/Types/Exception/SerializationFailedTest.php b/tests/Types/Exception/SerializationFailedTest.php index 680d4ff2e41..79781240a56 100644 --- a/tests/Types/Exception/SerializationFailedTest.php +++ b/tests/Types/Exception/SerializationFailedTest.php @@ -22,7 +22,7 @@ public function testNew(): void $exception = SerializationFailed::new($value, 'json', json_last_error_msg()); self::assertSame( - 'Could not convert PHP type "double" to "json". An error was triggered by the serialization: ' + 'Could not convert PHP type "float" to "json". An error was triggered by the serialization: ' . 'Inf and NaN cannot be JSON encoded', $exception->getMessage() ); diff --git a/tests/Types/TimeImmutableTypeTest.php b/tests/Types/TimeImmutableTypeTest.php index 1c2caa7d02f..acc2fdd3b99 100644 --- a/tests/Types/TimeImmutableTypeTest.php +++ b/tests/Types/TimeImmutableTypeTest.php @@ -105,6 +105,7 @@ public function testResetDateFractionsWhenConvertingToPHPValue(): void $date = $this->type->convertToPHPValue('15:58:59', $this->platform); + self::assertNotNull($date); self::assertSame('1970-01-01 15:58:59', $date->format('Y-m-d H:i:s')); }