diff --git a/.gitignore b/.gitignore index d342cc0b4..03c13ebee 100644 --- a/.gitignore +++ b/.gitignore @@ -61,10 +61,12 @@ doctrine/dbal/.doctrine-project.json doctrine/dbal/.gitmodules doctrine/dbal/build.* doctrine/dbal/docs +doctrine/dbal/phpstan-baseline.neon doctrine/dbal/run-all.sh doctrine/dbal/static-analysis doctrine/event-manager/phpstan.neon.dist +doctrine/event-manager/psalm-baseline.xml fusonic/linq/examples/ diff --git a/composer.json b/composer.json index a0840a3ee..497e69c1e 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "cweagans/composer-patches": "^1.7", "deepdiver/zipstreamer": "^2.0.3", "deepdiver1975/tarstreamer": "^2.1.0", - "doctrine/dbal": "^3.9.1", + "doctrine/dbal": "^3.9.4", "egulias/email-validator": "^4.0.2", "fusonic/opengraph": "^2.3.0", "giggsey/libphonenumber-for-php-lite": "^8.13.48", diff --git a/composer.lock b/composer.lock index 14188e3e8..f438711aa 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "678b927ba29cbe49f1995c6df1fc51a6", + "content-hash": "b19a7af2d8e01cd5d41d5d1ba2e256ca", "packages": [ { "name": "aws/aws-crt-php", @@ -528,16 +528,16 @@ }, { "name": "doctrine/dbal", - "version": "3.9.1", + "version": "3.9.4", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "d7dc08f98cba352b2bab5d32c5e58f7e745c11a7" + "reference": "ec16c82f20be1a7224e65ac67144a29199f87959" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/d7dc08f98cba352b2bab5d32c5e58f7e745c11a7", - "reference": "d7dc08f98cba352b2bab5d32c5e58f7e745c11a7", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/ec16c82f20be1a7224e65ac67144a29199f87959", + "reference": "ec16c82f20be1a7224e65ac67144a29199f87959", "shasum": "" }, "require": { @@ -553,15 +553,13 @@ "doctrine/coding-standard": "12.0.0", "fig/log-test": "^1", "jetbrains/phpstorm-stubs": "2023.1", - "phpstan/phpstan": "1.12.0", - "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpunit": "9.6.20", - "psalm/plugin-phpunit": "0.18.4", + "phpstan/phpstan": "2.1.1", + "phpstan/phpstan-strict-rules": "^2", + "phpunit/phpunit": "9.6.22", "slevomat/coding-standard": "8.13.1", "squizlabs/php_codesniffer": "3.10.2", "symfony/cache": "^5.4|^6.0|^7.0", - "symfony/console": "^4.4|^5.4|^6.0|^7.0", - "vimeo/psalm": "4.30.0" + "symfony/console": "^4.4|^5.4|^6.0|^7.0" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." @@ -621,7 +619,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.9.1" + "source": "https://github.com/doctrine/dbal/tree/3.9.4" }, "funding": [ { @@ -637,7 +635,7 @@ "type": "tidelift" } ], - "time": "2024-09-01T13:49:23+00:00" + "time": "2025-01-16T08:28:55+00:00" }, { "name": "doctrine/deprecations", @@ -686,30 +684,29 @@ }, { "name": "doctrine/event-manager", - "version": "1.2.0", + "version": "2.0.1", "source": { "type": "git", "url": "https://github.com/doctrine/event-manager.git", - "reference": "95aa4cb529f1e96576f3fda9f5705ada4056a520" + "reference": "b680156fa328f1dfd874fd48c7026c41570b9c6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/event-manager/zipball/95aa4cb529f1e96576f3fda9f5705ada4056a520", - "reference": "95aa4cb529f1e96576f3fda9f5705ada4056a520", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/b680156fa328f1dfd874fd48c7026c41570b9c6e", + "reference": "b680156fa328f1dfd874fd48c7026c41570b9c6e", "shasum": "" }, "require": { - "doctrine/deprecations": "^0.5.3 || ^1", - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "conflict": { "doctrine/common": "<2.9" }, "require-dev": { - "doctrine/coding-standard": "^9 || ^10", - "phpstan/phpstan": "~1.4.10 || ^1.8.8", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.24" + "doctrine/coding-standard": "^12", + "phpstan/phpstan": "^1.8.8", + "phpunit/phpunit": "^10.5", + "vimeo/psalm": "^5.24" }, "type": "library", "autoload": { @@ -758,7 +755,7 @@ ], "support": { "issues": "https://github.com/doctrine/event-manager/issues", - "source": "https://github.com/doctrine/event-manager/tree/1.2.0" + "source": "https://github.com/doctrine/event-manager/tree/2.0.1" }, "funding": [ { @@ -774,7 +771,7 @@ "type": "tidelift" } ], - "time": "2022-10-12T20:51:15+00:00" + "time": "2024-05-22T20:47:39+00:00" }, { "name": "doctrine/lexer", diff --git a/composer/autoload_classmap.php b/composer/autoload_classmap.php index 62e82fe12..f564e93bd 100644 --- a/composer/autoload_classmap.php +++ b/composer/autoload_classmap.php @@ -1413,6 +1413,7 @@ 'Doctrine\\DBAL\\Exception\\SyntaxErrorException' => $vendorDir . '/doctrine/dbal/src/Exception/SyntaxErrorException.php', 'Doctrine\\DBAL\\Exception\\TableExistsException' => $vendorDir . '/doctrine/dbal/src/Exception/TableExistsException.php', 'Doctrine\\DBAL\\Exception\\TableNotFoundException' => $vendorDir . '/doctrine/dbal/src/Exception/TableNotFoundException.php', + 'Doctrine\\DBAL\\Exception\\TransactionRolledBack' => $vendorDir . '/doctrine/dbal/src/Exception/TransactionRolledBack.php', 'Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException' => $vendorDir . '/doctrine/dbal/src/Exception/UniqueConstraintViolationException.php', 'Doctrine\\DBAL\\ExpandArrayParameters' => $vendorDir . '/doctrine/dbal/src/ExpandArrayParameters.php', 'Doctrine\\DBAL\\FetchMode' => $vendorDir . '/doctrine/dbal/src/FetchMode.php', diff --git a/composer/autoload_static.php b/composer/autoload_static.php index 72939b2ce..eafab4a9c 100644 --- a/composer/autoload_static.php +++ b/composer/autoload_static.php @@ -1946,6 +1946,7 @@ class ComposerStaticInit2f23f73bc0cc116b4b1eee1521aa8652 'Doctrine\\DBAL\\Exception\\SyntaxErrorException' => __DIR__ . '/..' . '/doctrine/dbal/src/Exception/SyntaxErrorException.php', 'Doctrine\\DBAL\\Exception\\TableExistsException' => __DIR__ . '/..' . '/doctrine/dbal/src/Exception/TableExistsException.php', 'Doctrine\\DBAL\\Exception\\TableNotFoundException' => __DIR__ . '/..' . '/doctrine/dbal/src/Exception/TableNotFoundException.php', + 'Doctrine\\DBAL\\Exception\\TransactionRolledBack' => __DIR__ . '/..' . '/doctrine/dbal/src/Exception/TransactionRolledBack.php', 'Doctrine\\DBAL\\Exception\\UniqueConstraintViolationException' => __DIR__ . '/..' . '/doctrine/dbal/src/Exception/UniqueConstraintViolationException.php', 'Doctrine\\DBAL\\ExpandArrayParameters' => __DIR__ . '/..' . '/doctrine/dbal/src/ExpandArrayParameters.php', 'Doctrine\\DBAL\\FetchMode' => __DIR__ . '/..' . '/doctrine/dbal/src/FetchMode.php', diff --git a/composer/installed.json b/composer/installed.json index da87147a9..c449b0c26 100644 --- a/composer/installed.json +++ b/composer/installed.json @@ -546,17 +546,17 @@ }, { "name": "doctrine/dbal", - "version": "3.9.1", - "version_normalized": "3.9.1.0", + "version": "3.9.4", + "version_normalized": "3.9.4.0", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "d7dc08f98cba352b2bab5d32c5e58f7e745c11a7" + "reference": "ec16c82f20be1a7224e65ac67144a29199f87959" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/d7dc08f98cba352b2bab5d32c5e58f7e745c11a7", - "reference": "d7dc08f98cba352b2bab5d32c5e58f7e745c11a7", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/ec16c82f20be1a7224e65ac67144a29199f87959", + "reference": "ec16c82f20be1a7224e65ac67144a29199f87959", "shasum": "" }, "require": { @@ -572,20 +572,18 @@ "doctrine/coding-standard": "12.0.0", "fig/log-test": "^1", "jetbrains/phpstorm-stubs": "2023.1", - "phpstan/phpstan": "1.12.0", - "phpstan/phpstan-strict-rules": "^1.6", - "phpunit/phpunit": "9.6.20", - "psalm/plugin-phpunit": "0.18.4", + "phpstan/phpstan": "2.1.1", + "phpstan/phpstan-strict-rules": "^2", + "phpunit/phpunit": "9.6.22", "slevomat/coding-standard": "8.13.1", "squizlabs/php_codesniffer": "3.10.2", "symfony/cache": "^5.4|^6.0|^7.0", - "symfony/console": "^4.4|^5.4|^6.0|^7.0", - "vimeo/psalm": "4.30.0" + "symfony/console": "^4.4|^5.4|^6.0|^7.0" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." }, - "time": "2024-09-01T13:49:23+00:00", + "time": "2025-01-16T08:28:55+00:00", "bin": [ "bin/doctrine-dbal" ], @@ -642,7 +640,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.9.1" + "source": "https://github.com/doctrine/dbal/tree/3.9.4" }, "funding": [ { @@ -710,33 +708,32 @@ }, { "name": "doctrine/event-manager", - "version": "1.2.0", - "version_normalized": "1.2.0.0", + "version": "2.0.1", + "version_normalized": "2.0.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/event-manager.git", - "reference": "95aa4cb529f1e96576f3fda9f5705ada4056a520" + "reference": "b680156fa328f1dfd874fd48c7026c41570b9c6e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/event-manager/zipball/95aa4cb529f1e96576f3fda9f5705ada4056a520", - "reference": "95aa4cb529f1e96576f3fda9f5705ada4056a520", + "url": "https://api.github.com/repos/doctrine/event-manager/zipball/b680156fa328f1dfd874fd48c7026c41570b9c6e", + "reference": "b680156fa328f1dfd874fd48c7026c41570b9c6e", "shasum": "" }, "require": { - "doctrine/deprecations": "^0.5.3 || ^1", - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "conflict": { "doctrine/common": "<2.9" }, "require-dev": { - "doctrine/coding-standard": "^9 || ^10", - "phpstan/phpstan": "~1.4.10 || ^1.8.8", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.24" + "doctrine/coding-standard": "^12", + "phpstan/phpstan": "^1.8.8", + "phpunit/phpunit": "^10.5", + "vimeo/psalm": "^5.24" }, - "time": "2022-10-12T20:51:15+00:00", + "time": "2024-05-22T20:47:39+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -785,7 +782,7 @@ ], "support": { "issues": "https://github.com/doctrine/event-manager/issues", - "source": "https://github.com/doctrine/event-manager/tree/1.2.0" + "source": "https://github.com/doctrine/event-manager/tree/2.0.1" }, "funding": [ { diff --git a/composer/installed.php b/composer/installed.php index 7472dfb49..5f6ca3650 100644 --- a/composer/installed.php +++ b/composer/installed.php @@ -83,9 +83,9 @@ 'dev_requirement' => false, ), 'doctrine/dbal' => array( - 'pretty_version' => '3.9.1', - 'version' => '3.9.1.0', - 'reference' => 'd7dc08f98cba352b2bab5d32c5e58f7e745c11a7', + 'pretty_version' => '3.9.4', + 'version' => '3.9.4.0', + 'reference' => 'ec16c82f20be1a7224e65ac67144a29199f87959', 'type' => 'library', 'install_path' => __DIR__ . '/../doctrine/dbal', 'aliases' => array(), @@ -101,9 +101,9 @@ 'dev_requirement' => false, ), 'doctrine/event-manager' => array( - 'pretty_version' => '1.2.0', - 'version' => '1.2.0.0', - 'reference' => '95aa4cb529f1e96576f3fda9f5705ada4056a520', + 'pretty_version' => '2.0.1', + 'version' => '2.0.1.0', + 'reference' => 'b680156fa328f1dfd874fd48c7026c41570b9c6e', 'type' => 'library', 'install_path' => __DIR__ . '/../doctrine/event-manager', 'aliases' => array(), diff --git a/doctrine/dbal/src/ArrayParameterType.php b/doctrine/dbal/src/ArrayParameterType.php index 65e1a29c2..d78cd5f16 100644 --- a/doctrine/dbal/src/ArrayParameterType.php +++ b/doctrine/dbal/src/ArrayParameterType.php @@ -27,9 +27,9 @@ final class ArrayParameterType /** * @internal * - * @psalm-param self::* $type + * @phpstan-param self::* $type * - * @psalm-return ParameterType::INTEGER|ParameterType::STRING|ParameterType::ASCII|ParameterType::BINARY + * @phpstan-return ParameterType::INTEGER|ParameterType::STRING|ParameterType::ASCII|ParameterType::BINARY */ public static function toElementParameterType(int $type): int { diff --git a/doctrine/dbal/src/ArrayParameters/Exception/MissingNamedParameter.php b/doctrine/dbal/src/ArrayParameters/Exception/MissingNamedParameter.php index cd9b9756a..8fd40a357 100644 --- a/doctrine/dbal/src/ArrayParameters/Exception/MissingNamedParameter.php +++ b/doctrine/dbal/src/ArrayParameters/Exception/MissingNamedParameter.php @@ -7,7 +7,6 @@ use function sprintf; -/** @psalm-immutable */ class MissingNamedParameter extends LogicException implements Exception { public static function new(string $name): self diff --git a/doctrine/dbal/src/ArrayParameters/Exception/MissingPositionalParameter.php b/doctrine/dbal/src/ArrayParameters/Exception/MissingPositionalParameter.php index f89a98b79..2cd311491 100644 --- a/doctrine/dbal/src/ArrayParameters/Exception/MissingPositionalParameter.php +++ b/doctrine/dbal/src/ArrayParameters/Exception/MissingPositionalParameter.php @@ -7,11 +7,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ class MissingPositionalParameter extends LogicException implements Exception { public static function new(int $index): self diff --git a/doctrine/dbal/src/Cache/CacheException.php b/doctrine/dbal/src/Cache/CacheException.php index 18e95d6be..fd10fd5d8 100644 --- a/doctrine/dbal/src/Cache/CacheException.php +++ b/doctrine/dbal/src/Cache/CacheException.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Exception; -/** @psalm-immutable */ class CacheException extends Exception { /** @return CacheException */ diff --git a/doctrine/dbal/src/Connection.php b/doctrine/dbal/src/Connection.php index b97567060..2902429f4 100644 --- a/doctrine/dbal/src/Connection.php +++ b/doctrine/dbal/src/Connection.php @@ -9,14 +9,19 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Driver\API\ExceptionConverter; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\Driver\Exception as TheDriverException; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Event\TransactionBeginEventArgs; use Doctrine\DBAL\Event\TransactionCommitEventArgs; use Doctrine\DBAL\Event\TransactionRollBackEventArgs; use Doctrine\DBAL\Exception\ConnectionLost; +use Doctrine\DBAL\Exception\DeadlockException; use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\InvalidArgumentException; +use Doctrine\DBAL\Exception\TransactionRolledBack; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; @@ -48,8 +53,8 @@ * A database abstraction-level connection that implements features like events, transaction isolation levels, * configuration, emulated transaction nesting, lazy connecting and more. * - * @psalm-import-type Params from DriverManager - * @psalm-consistent-constructor + * @phpstan-import-type Params from DriverManager + * @phpstan-consistent-constructor */ class Connection { @@ -131,7 +136,7 @@ class Connection * The parameters used during creation of the Connection instance. * * @var array - * @psalm-var Params + * @phpstan-var Params */ private array $params; @@ -175,7 +180,7 @@ class Connection * @param Driver $driver The driver to use. * @param Configuration|null $config The configuration, optional. * @param EventManager|null $eventManager The event manager, optional. - * @psalm-param Params $params + * @phpstan-param Params $params * * @throws Exception */ @@ -239,7 +244,7 @@ public function __construct( * @internal * * @return array - * @psalm-return Params + * @phpstan-return Params */ public function getParams() { @@ -360,7 +365,7 @@ public function getExpressionBuilder() * * @throws Exception * - * @psalm-assert !null $this->_conn + * @phpstan-assert !null $this->_conn */ public function connect() { @@ -1278,16 +1283,41 @@ public function lastInsertId($name = null) public function transactional(Closure $func) { $this->beginTransaction(); + + $successful = false; + try { $res = $func($this); + + $successful = true; + } finally { + if (! $successful) { + $this->rollBack(); + } + } + + $shouldRollback = true; + try { $this->commit(); - return $res; - } catch (Throwable $e) { - $this->rollBack(); + $shouldRollback = false; + } catch (TheDriverException $t) { + $convertedException = $this->handleDriverException($t, null); + $shouldRollback = ! ( + $convertedException instanceof TransactionRolledBack + || $convertedException instanceof UniqueConstraintViolationException + || $convertedException instanceof ForeignKeyConstraintViolationException + || $convertedException instanceof DeadlockException + ); - throw $e; + throw $t; + } finally { + if ($shouldRollback) { + $this->rollBack(); + } } + + return $res; } /** @@ -1419,12 +1449,21 @@ public function commit() $connection = $this->getWrappedConnection(); - if ($this->transactionNestingLevel === 1) { - $result = $this->doCommit($connection); - } elseif ($this->nestTransactionsWithSavepoints) { - $this->releaseSavepoint($this->_getNestedTransactionSavePointName()); + try { + if ($this->transactionNestingLevel === 1) { + $result = $this->doCommit($connection); + } elseif ($this->nestTransactionsWithSavepoints) { + $this->releaseSavepoint($this->_getNestedTransactionSavePointName()); + } + } finally { + $this->updateTransactionStateAfterCommit(); } + return $result; + } + + private function updateTransactionStateAfterCommit(): void + { --$this->transactionNestingLevel; $eventManager = $this->getEventManager(); @@ -1441,12 +1480,10 @@ public function commit() } if ($this->autoCommit !== false || $this->transactionNestingLevel !== 0) { - return $result; + return; } $this->beginTransaction(); - - return $result; } /** diff --git a/doctrine/dbal/src/ConnectionException.php b/doctrine/dbal/src/ConnectionException.php index f1e18987b..49d9efe41 100644 --- a/doctrine/dbal/src/ConnectionException.php +++ b/doctrine/dbal/src/ConnectionException.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL; -/** @psalm-immutable */ class ConnectionException extends Exception { /** @return ConnectionException */ diff --git a/doctrine/dbal/src/Connections/PrimaryReadReplicaConnection.php b/doctrine/dbal/src/Connections/PrimaryReadReplicaConnection.php index 2617fb802..0a6d13744 100644 --- a/doctrine/dbal/src/Connections/PrimaryReadReplicaConnection.php +++ b/doctrine/dbal/src/Connections/PrimaryReadReplicaConnection.php @@ -59,7 +59,7 @@ * * Instantiation through the DriverManager looks like: * - * @psalm-import-type Params from DriverManager + * @phpstan-import-type Params from DriverManager * @example * * $conn = DriverManager::getConnection(array( @@ -98,7 +98,7 @@ class PrimaryReadReplicaConnection extends Connection * @internal The connection can be only instantiated by the driver manager. * * @param array $params - * @psalm-param Params $params + * @phpstan-param Params $params * * @throws Exception * @throws InvalidArgumentException diff --git a/doctrine/dbal/src/Driver.php b/doctrine/dbal/src/Driver.php index 46e422ba9..a376f069b 100644 --- a/doctrine/dbal/src/Driver.php +++ b/doctrine/dbal/src/Driver.php @@ -13,7 +13,7 @@ * Driver interface. * Interface that all DBAL drivers must implement. * - * @psalm-import-type Params from DriverManager + * @phpstan-import-type Params from DriverManager */ interface Driver { @@ -21,7 +21,7 @@ interface Driver * Attempts to create a connection with the database. * * @param array $params All connection parameters. - * @psalm-param Params $params All connection parameters. + * @phpstan-param Params $params All connection parameters. * * @return DriverConnection The database connection. * diff --git a/doctrine/dbal/src/Driver/API/OCI/ExceptionConverter.php b/doctrine/dbal/src/Driver/API/OCI/ExceptionConverter.php index 4703a57d5..62a08a799 100644 --- a/doctrine/dbal/src/Driver/API/OCI/ExceptionConverter.php +++ b/doctrine/dbal/src/Driver/API/OCI/ExceptionConverter.php @@ -6,6 +6,8 @@ use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface; use Doctrine\DBAL\Driver\Exception; +use Doctrine\DBAL\Driver\OCI8\Exception\Error; +use Doctrine\DBAL\Driver\PDO\PDOException; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\DatabaseDoesNotExist; use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException; @@ -17,16 +19,30 @@ use Doctrine\DBAL\Exception\SyntaxErrorException; use Doctrine\DBAL\Exception\TableExistsException; use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Exception\TransactionRolledBack; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Query; +use function explode; +use function str_replace; + /** @internal */ final class ExceptionConverter implements ExceptionConverterInterface { /** @link http://www.dba-oracle.com/t_error_code_list.htm */ public function convert(Exception $exception, ?Query $query): DriverException { - switch ($exception->getCode()) { + /** @phpstan-var int|'HY000' $code */ // @phpstan-ignore varTag.type + $code = $exception->getCode(); + // @phpstan-ignore property.notFound, property.notFound + if ($code === 'HY000' && isset($exception->errorInfo[1], $exception->errorInfo[2])) { + $errorInfo = $exception->errorInfo; + $exception = new PDOException($errorInfo[2], $errorInfo[1]); + $exception->errorInfo = $errorInfo; + $code = $exception->getCode(); + } + + switch ($code) { case 1: case 2299: case 38911: @@ -58,6 +74,22 @@ public function convert(Exception $exception, ?Query $query): DriverException case 1918: return new DatabaseDoesNotExist($exception, $query); + case 2091: + //ORA-02091: transaction rolled back + //ORA-00001: unique constraint (DOCTRINE.GH3423_UNIQUE) violated + [, $causeError] = explode("\n", $exception->getMessage(), 2); + + [$causeCode] = explode(': ', $causeError, 2); + $code = (int) str_replace('ORA-', '', $causeCode); + + if ($exception instanceof PDOException) { + $why = $this->convert(new PDOException($causeError, $code, $exception), $query); + } else { + $why = $this->convert(new Error($causeError, null, $code, $exception), $query); + } + + return new TransactionRolledBack($why, $query); + case 2289: case 2443: case 4080: diff --git a/doctrine/dbal/src/Driver/AbstractException.php b/doctrine/dbal/src/Driver/AbstractException.php index 389f82e70..9b7bff40f 100644 --- a/doctrine/dbal/src/Driver/AbstractException.php +++ b/doctrine/dbal/src/Driver/AbstractException.php @@ -11,8 +11,6 @@ * Base implementation of the {@see Exception} interface. * * @internal - * - * @psalm-immutable */ abstract class AbstractException extends BaseException implements Exception { diff --git a/doctrine/dbal/src/Driver/AbstractSQLServerDriver/Exception/PortWithoutHost.php b/doctrine/dbal/src/Driver/AbstractSQLServerDriver/Exception/PortWithoutHost.php index ea8dcc461..3b2665617 100644 --- a/doctrine/dbal/src/Driver/AbstractSQLServerDriver/Exception/PortWithoutHost.php +++ b/doctrine/dbal/src/Driver/AbstractSQLServerDriver/Exception/PortWithoutHost.php @@ -6,11 +6,7 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class PortWithoutHost extends AbstractException { public static function new(): self diff --git a/doctrine/dbal/src/Driver/Exception.php b/doctrine/dbal/src/Driver/Exception.php index f963563b8..cf824a5f5 100644 --- a/doctrine/dbal/src/Driver/Exception.php +++ b/doctrine/dbal/src/Driver/Exception.php @@ -6,7 +6,6 @@ use Throwable; -/** @psalm-immutable */ interface Exception extends Throwable { /** diff --git a/doctrine/dbal/src/Driver/Exception/UnknownParameterType.php b/doctrine/dbal/src/Driver/Exception/UnknownParameterType.php index 01a9b3d0c..a7490cc7a 100644 --- a/doctrine/dbal/src/Driver/Exception/UnknownParameterType.php +++ b/doctrine/dbal/src/Driver/Exception/UnknownParameterType.php @@ -8,11 +8,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class UnknownParameterType extends AbstractException { /** @param mixed $type */ diff --git a/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php b/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php index 231c9d473..05099faf0 100644 --- a/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php +++ b/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCopyStreamToStream.php @@ -6,14 +6,10 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class CannotCopyStreamToStream extends AbstractException { - /** @psalm-param array{message: string}|null $error */ + /** @param array{message: string}|null $error */ public static function new(?array $error): self { $message = 'Could not copy source stream to temporary file'; diff --git a/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php b/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php index 63f7ca1e2..70a355732 100644 --- a/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php +++ b/doctrine/dbal/src/Driver/IBMDB2/Exception/CannotCreateTemporaryFile.php @@ -6,14 +6,10 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class CannotCreateTemporaryFile extends AbstractException { - /** @psalm-param array{message: string}|null $error */ + /** @param array{message: string}|null $error */ public static function new(?array $error): self { $message = 'Could not create temporary file'; diff --git a/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionError.php b/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionError.php index b7bd8be69..c6c40b93f 100644 --- a/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionError.php +++ b/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionError.php @@ -9,11 +9,7 @@ use function db2_conn_error; use function db2_conn_errormsg; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class ConnectionError extends AbstractException { /** @param resource $connection */ diff --git a/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionFailed.php b/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionFailed.php index 9dd04434e..0826e5c92 100644 --- a/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionFailed.php +++ b/doctrine/dbal/src/Driver/IBMDB2/Exception/ConnectionFailed.php @@ -9,11 +9,7 @@ use function db2_conn_error; use function db2_conn_errormsg; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class ConnectionFailed extends AbstractException { public static function new(): self diff --git a/doctrine/dbal/src/Driver/IBMDB2/Exception/Factory.php b/doctrine/dbal/src/Driver/IBMDB2/Exception/Factory.php index 91b9b439c..d2d30127e 100644 --- a/doctrine/dbal/src/Driver/IBMDB2/Exception/Factory.php +++ b/doctrine/dbal/src/Driver/IBMDB2/Exception/Factory.php @@ -8,11 +8,7 @@ use function preg_match; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class Factory { /** diff --git a/doctrine/dbal/src/Driver/IBMDB2/Exception/PrepareFailed.php b/doctrine/dbal/src/Driver/IBMDB2/Exception/PrepareFailed.php index 42df5e15c..95da1cdc3 100644 --- a/doctrine/dbal/src/Driver/IBMDB2/Exception/PrepareFailed.php +++ b/doctrine/dbal/src/Driver/IBMDB2/Exception/PrepareFailed.php @@ -6,14 +6,10 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class PrepareFailed extends AbstractException { - /** @psalm-param array{message: string}|null $error */ + /** @param array{message: string}|null $error */ public static function new(?array $error): self { if ($error === null) { diff --git a/doctrine/dbal/src/Driver/IBMDB2/Exception/StatementError.php b/doctrine/dbal/src/Driver/IBMDB2/Exception/StatementError.php index 6bf851131..d4c0d0bd1 100644 --- a/doctrine/dbal/src/Driver/IBMDB2/Exception/StatementError.php +++ b/doctrine/dbal/src/Driver/IBMDB2/Exception/StatementError.php @@ -9,11 +9,7 @@ use function db2_stmt_error; use function db2_stmt_errormsg; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class StatementError extends AbstractException { /** @param resource|null $statement */ diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionError.php b/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionError.php index ef5b98017..f5755932b 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionError.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionError.php @@ -9,11 +9,7 @@ use mysqli_sql_exception; use ReflectionProperty; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class ConnectionError extends AbstractException { public static function new(mysqli $connection): self diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php b/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php index 44a8cab99..051f141fd 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/ConnectionFailed.php @@ -11,11 +11,7 @@ use function assert; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class ConnectionFailed extends AbstractException { public static function new(mysqli $connection): self diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/FailedReadingStreamOffset.php b/doctrine/dbal/src/Driver/Mysqli/Exception/FailedReadingStreamOffset.php index 6f26dbec8..f20d8bc1d 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/FailedReadingStreamOffset.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/FailedReadingStreamOffset.php @@ -8,11 +8,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class FailedReadingStreamOffset extends AbstractException { public static function new(int $parameter): self diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/HostRequired.php b/doctrine/dbal/src/Driver/Mysqli/Exception/HostRequired.php index d3359fcdf..644f3fd5e 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/HostRequired.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/HostRequired.php @@ -6,11 +6,7 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class HostRequired extends AbstractException { public static function forPersistentConnection(): self diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php b/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php index 8c6bbb476..71a5bc60b 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidCharset.php @@ -11,11 +11,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class InvalidCharset extends AbstractException { public static function fromCharset(mysqli $connection, string $charset): self diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidOption.php b/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidOption.php index 6fb46316e..abbda01c0 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidOption.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/InvalidOption.php @@ -8,11 +8,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class InvalidOption extends AbstractException { /** @param mixed $value */ diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/NonStreamResourceUsedAsLargeObject.php b/doctrine/dbal/src/Driver/Mysqli/Exception/NonStreamResourceUsedAsLargeObject.php index 566d63638..7b50de545 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/NonStreamResourceUsedAsLargeObject.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/NonStreamResourceUsedAsLargeObject.php @@ -8,11 +8,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class NonStreamResourceUsedAsLargeObject extends AbstractException { public static function new(int $parameter): self diff --git a/doctrine/dbal/src/Driver/Mysqli/Exception/StatementError.php b/doctrine/dbal/src/Driver/Mysqli/Exception/StatementError.php index 78dc8556b..716e2cd24 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Exception/StatementError.php +++ b/doctrine/dbal/src/Driver/Mysqli/Exception/StatementError.php @@ -9,11 +9,7 @@ use mysqli_stmt; use ReflectionProperty; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class StatementError extends AbstractException { public static function new(mysqli_stmt $statement): self diff --git a/doctrine/dbal/src/Driver/Mysqli/Result.php b/doctrine/dbal/src/Driver/Mysqli/Result.php index c7dc65d1d..bfd558b4f 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Result.php +++ b/doctrine/dbal/src/Driver/Mysqli/Result.php @@ -20,6 +20,15 @@ final class Result implements ResultInterface { private mysqli_stmt $statement; + /** + * Maintains a reference to the Statement that generated this result. This ensures that the lifetime of the + * Statement is managed in conjunction with its associated results, so they are destroyed together + * at the appropriate time {@see Statement::__destruct()}. + * + * @phpstan-ignore property.onlyWritten + */ + private ?Statement $statementReference = null; + /** * Whether the statement result has columns. The property should be used only after the result metadata * has been fetched ({@see $metadataFetched}). Otherwise, the property value is undetermined. @@ -42,9 +51,12 @@ final class Result implements ResultInterface * * @throws Exception */ - public function __construct(mysqli_stmt $statement) - { - $this->statement = $statement; + public function __construct( + mysqli_stmt $statement, + ?Statement $statementReference = null + ) { + $this->statement = $statement; + $this->statementReference = $statementReference; $meta = $statement->result_metadata(); diff --git a/doctrine/dbal/src/Driver/Mysqli/Statement.php b/doctrine/dbal/src/Driver/Mysqli/Statement.php index fec7c95c3..be555e3dd 100644 --- a/doctrine/dbal/src/Driver/Mysqli/Statement.php +++ b/doctrine/dbal/src/Driver/Mysqli/Statement.php @@ -61,12 +61,17 @@ public function __construct(mysqli_stmt $stmt) $this->boundValues = array_fill(1, $paramCount, null); } + public function __destruct() + { + @$this->stmt->close(); + } + /** * @deprecated Use {@see bindValue()} instead. * * {@inheritDoc} * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool { @@ -101,7 +106,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le /** * {@inheritDoc} * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindValue($param, $value, $type = ParameterType::STRING): bool { @@ -159,7 +164,7 @@ public function execute($params = null): ResultInterface throw StatementError::new($this->stmt); } - return new Result($this->stmt); + return new Result($this->stmt, $this); } /** diff --git a/doctrine/dbal/src/Driver/OCI8/Connection.php b/doctrine/dbal/src/Driver/OCI8/Connection.php index 72353fa31..155b2d1d3 100644 --- a/doctrine/dbal/src/Driver/OCI8/Connection.php +++ b/doctrine/dbal/src/Driver/OCI8/Connection.php @@ -142,7 +142,7 @@ public function beginTransaction(): bool public function commit(): bool { - if (! oci_commit($this->connection)) { + if (! @oci_commit($this->connection)) { throw Error::new($this->connection); } diff --git a/doctrine/dbal/src/Driver/OCI8/Exception/ConnectionFailed.php b/doctrine/dbal/src/Driver/OCI8/Exception/ConnectionFailed.php index cefe9a3ad..691d1e31f 100644 --- a/doctrine/dbal/src/Driver/OCI8/Exception/ConnectionFailed.php +++ b/doctrine/dbal/src/Driver/OCI8/Exception/ConnectionFailed.php @@ -9,11 +9,7 @@ use function assert; use function oci_error; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class ConnectionFailed extends AbstractException { public static function new(): self diff --git a/doctrine/dbal/src/Driver/OCI8/Exception/Error.php b/doctrine/dbal/src/Driver/OCI8/Exception/Error.php index 6abdf233c..9e627c77a 100644 --- a/doctrine/dbal/src/Driver/OCI8/Exception/Error.php +++ b/doctrine/dbal/src/Driver/OCI8/Exception/Error.php @@ -9,11 +9,7 @@ use function assert; use function oci_error; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class Error extends AbstractException { /** @param resource $resource */ diff --git a/doctrine/dbal/src/Driver/OCI8/Exception/InvalidConfiguration.php b/doctrine/dbal/src/Driver/OCI8/Exception/InvalidConfiguration.php index e9d2d0ebd..ef3bb29de 100644 --- a/doctrine/dbal/src/Driver/OCI8/Exception/InvalidConfiguration.php +++ b/doctrine/dbal/src/Driver/OCI8/Exception/InvalidConfiguration.php @@ -6,11 +6,7 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class InvalidConfiguration extends AbstractException { public static function forPersistentAndExclusive(): self diff --git a/doctrine/dbal/src/Driver/OCI8/Exception/NonTerminatedStringLiteral.php b/doctrine/dbal/src/Driver/OCI8/Exception/NonTerminatedStringLiteral.php index 776728fbe..fab0b27a8 100644 --- a/doctrine/dbal/src/Driver/OCI8/Exception/NonTerminatedStringLiteral.php +++ b/doctrine/dbal/src/Driver/OCI8/Exception/NonTerminatedStringLiteral.php @@ -8,11 +8,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class NonTerminatedStringLiteral extends AbstractException { public static function new(int $offset): self diff --git a/doctrine/dbal/src/Driver/OCI8/Exception/SequenceDoesNotExist.php b/doctrine/dbal/src/Driver/OCI8/Exception/SequenceDoesNotExist.php index 5fa43caba..c31c35142 100644 --- a/doctrine/dbal/src/Driver/OCI8/Exception/SequenceDoesNotExist.php +++ b/doctrine/dbal/src/Driver/OCI8/Exception/SequenceDoesNotExist.php @@ -6,11 +6,7 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class SequenceDoesNotExist extends AbstractException { public static function new(): self diff --git a/doctrine/dbal/src/Driver/OCI8/Exception/UnknownParameterIndex.php b/doctrine/dbal/src/Driver/OCI8/Exception/UnknownParameterIndex.php index 2cd3fe796..d39bb4547 100644 --- a/doctrine/dbal/src/Driver/OCI8/Exception/UnknownParameterIndex.php +++ b/doctrine/dbal/src/Driver/OCI8/Exception/UnknownParameterIndex.php @@ -8,11 +8,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class UnknownParameterIndex extends AbstractException { public static function new(int $index): self diff --git a/doctrine/dbal/src/Driver/PDO/Connection.php b/doctrine/dbal/src/Driver/PDO/Connection.php index 290dcc2d2..4320879c8 100644 --- a/doctrine/dbal/src/Driver/PDO/Connection.php +++ b/doctrine/dbal/src/Driver/PDO/Connection.php @@ -82,7 +82,7 @@ public function query(string $sql): ResultInterface * * @throws UnknownParameterType * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function quote($value, $type = ParameterType::STRING) { diff --git a/doctrine/dbal/src/Driver/PDO/Exception.php b/doctrine/dbal/src/Driver/PDO/Exception.php index fbb81253b..0c0d1554b 100644 --- a/doctrine/dbal/src/Driver/PDO/Exception.php +++ b/doctrine/dbal/src/Driver/PDO/Exception.php @@ -7,11 +7,7 @@ use Doctrine\DBAL\Driver\AbstractException; use PDOException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class Exception extends AbstractException { public static function new(PDOException $exception): self diff --git a/doctrine/dbal/src/Driver/PDO/PDOException.php b/doctrine/dbal/src/Driver/PDO/PDOException.php index 6eefda40a..4b0b177d2 100644 --- a/doctrine/dbal/src/Driver/PDO/PDOException.php +++ b/doctrine/dbal/src/Driver/PDO/PDOException.php @@ -6,11 +6,7 @@ use Doctrine\DBAL\Driver\Exception as DriverException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class PDOException extends \PDOException implements DriverException { private ?string $sqlState = null; diff --git a/doctrine/dbal/src/Driver/PDO/ParameterTypeMap.php b/doctrine/dbal/src/Driver/PDO/ParameterTypeMap.php index f17b585f7..af705b032 100644 --- a/doctrine/dbal/src/Driver/PDO/ParameterTypeMap.php +++ b/doctrine/dbal/src/Driver/PDO/ParameterTypeMap.php @@ -24,11 +24,11 @@ final class ParameterTypeMap /** * Converts DBAL parameter type to PDO parameter type * - * @psalm-return PDO::PARAM_* + * @phpstan-return PDO::PARAM_* * * @throws UnknownParameterType * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public static function convertParamType(int $type): int { diff --git a/doctrine/dbal/src/Driver/PDO/Result.php b/doctrine/dbal/src/Driver/PDO/Result.php index 67970ac56..506fdd4a9 100644 --- a/doctrine/dbal/src/Driver/PDO/Result.php +++ b/doctrine/dbal/src/Driver/PDO/Result.php @@ -91,7 +91,7 @@ public function free(): void } /** - * @psalm-param PDO::FETCH_* $mode + * @phpstan-param PDO::FETCH_* $mode * * @return mixed * @@ -107,7 +107,7 @@ private function fetch(int $mode) } /** - * @psalm-param PDO::FETCH_* $mode + * @phpstan-param PDO::FETCH_* $mode * * @return list * diff --git a/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php b/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php index cb2dfaedb..a63ff79d7 100644 --- a/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php +++ b/doctrine/dbal/src/Driver/PDO/SQLSrv/Statement.php @@ -36,7 +36,7 @@ public function __construct(PDOStatement $statement) * * @throws UnknownParameterType * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindParam( $param, @@ -91,7 +91,7 @@ public function bindParam( * * {@inheritDoc} * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindValue($param, $value, $type = ParameterType::STRING): bool { diff --git a/doctrine/dbal/src/Driver/PDO/Statement.php b/doctrine/dbal/src/Driver/PDO/Statement.php index 64f318d2c..e631fad3d 100644 --- a/doctrine/dbal/src/Driver/PDO/Statement.php +++ b/doctrine/dbal/src/Driver/PDO/Statement.php @@ -29,7 +29,7 @@ public function __construct(PDOStatement $stmt) * * @throws UnknownParameterType * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindValue($param, $value, $type = ParameterType::STRING) { @@ -64,7 +64,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING) * * @throws UnknownParameterType * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindParam( $param, diff --git a/doctrine/dbal/src/Driver/PgSQL/Exception.php b/doctrine/dbal/src/Driver/PgSQL/Exception.php index 41e0dff19..5e7086ba0 100644 --- a/doctrine/dbal/src/Driver/PgSQL/Exception.php +++ b/doctrine/dbal/src/Driver/PgSQL/Exception.php @@ -10,11 +10,7 @@ use const PGSQL_DIAG_MESSAGE_PRIMARY; use const PGSQL_DIAG_SQLSTATE; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class Exception extends AbstractException { /** @param PgSqlResult|resource $result */ diff --git a/doctrine/dbal/src/Driver/PgSQL/Exception/UnexpectedValue.php b/doctrine/dbal/src/Driver/PgSQL/Exception/UnexpectedValue.php index ef69817b7..d295cf5e8 100644 --- a/doctrine/dbal/src/Driver/PgSQL/Exception/UnexpectedValue.php +++ b/doctrine/dbal/src/Driver/PgSQL/Exception/UnexpectedValue.php @@ -9,7 +9,6 @@ use function sprintf; -/** @psalm-immutable */ final class UnexpectedValue extends UnexpectedValueException implements Exception { public static function new(string $value, string $type): self diff --git a/doctrine/dbal/src/Driver/PgSQL/Exception/UnknownParameter.php b/doctrine/dbal/src/Driver/PgSQL/Exception/UnknownParameter.php index 4619ecc0d..dd4b2694d 100644 --- a/doctrine/dbal/src/Driver/PgSQL/Exception/UnknownParameter.php +++ b/doctrine/dbal/src/Driver/PgSQL/Exception/UnknownParameter.php @@ -6,7 +6,6 @@ use function sprintf; -/** @psalm-immutable */ final class UnknownParameter extends AbstractException { public static function new(string $param): self diff --git a/doctrine/dbal/src/Driver/PgSQL/Statement.php b/doctrine/dbal/src/Driver/PgSQL/Statement.php index 75af66f30..ca6aa3b10 100644 --- a/doctrine/dbal/src/Driver/PgSQL/Statement.php +++ b/doctrine/dbal/src/Driver/PgSQL/Statement.php @@ -40,7 +40,7 @@ final class Statement implements StatementInterface /** @var array */ private array $parameters = []; - /** @psalm-var array */ + /** @var array */ private array $parameterTypes = []; /** diff --git a/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php b/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php index f39d5fc4c..e9adb0528 100644 --- a/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php +++ b/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php @@ -11,11 +11,7 @@ use const SQLSRV_ERR_ERRORS; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class Error extends AbstractException { public static function new(): self diff --git a/doctrine/dbal/src/Driver/SQLite3/Exception.php b/doctrine/dbal/src/Driver/SQLite3/Exception.php index 3ca1190bc..3219fc327 100644 --- a/doctrine/dbal/src/Driver/SQLite3/Exception.php +++ b/doctrine/dbal/src/Driver/SQLite3/Exception.php @@ -4,11 +4,7 @@ use Doctrine\DBAL\Driver\AbstractException; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class Exception extends AbstractException { public static function new(\Exception $exception): self diff --git a/doctrine/dbal/src/Driver/SQLite3/Statement.php b/doctrine/dbal/src/Driver/SQLite3/Statement.php index a4166aa61..01c3b8bbb 100644 --- a/doctrine/dbal/src/Driver/SQLite3/Statement.php +++ b/doctrine/dbal/src/Driver/SQLite3/Statement.php @@ -45,7 +45,7 @@ public function __construct(SQLite3 $connection, SQLite3Stmt $statement) * * {@inheritDoc} * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindValue($param, $value, $type = ParameterType::STRING): bool { @@ -66,7 +66,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING): bool * * {@inheritDoc} * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null): bool { @@ -121,9 +121,9 @@ public function execute($params = null): Result } /** - * @psalm-return value-of + * @phpstan-return value-of * - * @psalm-assert ParameterType::* $type + * @phpstan-assert ParameterType::* $type */ private function convertParamType(int $type): int { diff --git a/doctrine/dbal/src/DriverManager.php b/doctrine/dbal/src/DriverManager.php index 056f42084..7586bc479 100644 --- a/doctrine/dbal/src/DriverManager.php +++ b/doctrine/dbal/src/DriverManager.php @@ -22,7 +22,7 @@ /** * Factory for creating {@see Connection} instances. * - * @psalm-type OverrideParams = array{ + * @phpstan-type OverrideParams = array{ * application_name?: string, * charset?: string, * dbname?: string, @@ -41,7 +41,7 @@ * user?: string, * unix_socket?: string, * } - * @psalm-type Params = array{ + * @phpstan-type Params = array{ * application_name?: string, * charset?: string, * dbname?: string, @@ -98,7 +98,7 @@ final class DriverManager * @deprecated Use actual driver names instead. * * @var array - * @psalm-var array> + * @phpstan-var array> */ private static array $driverSchemeAliases = [ 'db2' => 'ibm_db2', @@ -153,9 +153,9 @@ private function __construct() * * @param Configuration|null $config The configuration to use. * @param EventManager|null $eventManager The event manager to use. - * @psalm-param Params $params + * @phpstan-param Params $params * - * @psalm-return ($params is array{wrapperClass: class-string} ? T : Connection) + * @phpstan-return ($params is array{wrapperClass: class-string} ? T : Connection) * * @throws Exception * @@ -201,7 +201,7 @@ public static function getConnection( * Returns the list of supported drivers. * * @return string[] - * @psalm-return list> + * @phpstan-return list> */ public static function getAvailableDrivers(): array { @@ -211,8 +211,8 @@ public static function getAvailableDrivers(): array /** * @throws Exception * - * @psalm-assert key-of|null $driver - * @psalm-assert class-string|null $driverClass + * @phpstan-assert key-of|null $driver + * @phpstan-assert class-string|null $driverClass */ private static function createDriver(?string $driver, ?string $driverClass): Driver { @@ -238,11 +238,11 @@ private static function createDriver(?string $driver, ?string $driverClass): Dri * updated list of parameters. * * @param mixed[] $params The list of parameters. - * @psalm-param Params $params + * @phpstan-param Params $params * * @return mixed[] A modified list of parameters with info from a database * URL extracted into indidivual parameter parts. - * @psalm-return Params + * @phpstan-return Params * * @throws Exception */ diff --git a/doctrine/dbal/src/Event/SchemaDropTableEventArgs.php b/doctrine/dbal/src/Event/SchemaDropTableEventArgs.php index f45e3a15a..6f279e965 100644 --- a/doctrine/dbal/src/Event/SchemaDropTableEventArgs.php +++ b/doctrine/dbal/src/Event/SchemaDropTableEventArgs.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\Table; -use InvalidArgumentException; /** * Event Arguments used when the SQL query for dropping tables are generated inside {@see AbstractPlatform}. @@ -21,11 +20,7 @@ class SchemaDropTableEventArgs extends SchemaEventArgs /** @var string|null */ private $sql; - /** - * @param string|Table $table - * - * @throws InvalidArgumentException - */ + /** @param string|Table $table */ public function __construct($table, AbstractPlatform $platform) { $this->table = $table; diff --git a/doctrine/dbal/src/Exception.php b/doctrine/dbal/src/Exception.php index 3d2814c73..8475a140d 100644 --- a/doctrine/dbal/src/Exception.php +++ b/doctrine/dbal/src/Exception.php @@ -13,7 +13,6 @@ use function spl_object_hash; use function sprintf; -/** @psalm-immutable */ class Exception extends \Exception { public static function notSupported(string $method): self diff --git a/doctrine/dbal/src/Exception/ConnectionException.php b/doctrine/dbal/src/Exception/ConnectionException.php index 6b7c901a3..e96a29191 100644 --- a/doctrine/dbal/src/Exception/ConnectionException.php +++ b/doctrine/dbal/src/Exception/ConnectionException.php @@ -4,8 +4,6 @@ /** * Base class for all connection related errors detected in the driver. - * - * @psalm-immutable */ class ConnectionException extends DriverException { diff --git a/doctrine/dbal/src/Exception/ConnectionLost.php b/doctrine/dbal/src/Exception/ConnectionLost.php index c45085839..1195d98e9 100644 --- a/doctrine/dbal/src/Exception/ConnectionLost.php +++ b/doctrine/dbal/src/Exception/ConnectionLost.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL\Exception; -/** @psalm-immutable */ final class ConnectionLost extends ConnectionException { } diff --git a/doctrine/dbal/src/Exception/ConstraintViolationException.php b/doctrine/dbal/src/Exception/ConstraintViolationException.php index 435e8b19f..3959f39af 100644 --- a/doctrine/dbal/src/Exception/ConstraintViolationException.php +++ b/doctrine/dbal/src/Exception/ConstraintViolationException.php @@ -4,8 +4,6 @@ /** * Base class for all constraint violation related errors detected in the driver. - * - * @psalm-immutable */ class ConstraintViolationException extends ServerException { diff --git a/doctrine/dbal/src/Exception/DatabaseDoesNotExist.php b/doctrine/dbal/src/Exception/DatabaseDoesNotExist.php index dc71c82cb..a49f6dec8 100644 --- a/doctrine/dbal/src/Exception/DatabaseDoesNotExist.php +++ b/doctrine/dbal/src/Exception/DatabaseDoesNotExist.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL\Exception; -/** @psalm-immutable */ class DatabaseDoesNotExist extends DatabaseObjectNotFoundException { } diff --git a/doctrine/dbal/src/Exception/DatabaseObjectExistsException.php b/doctrine/dbal/src/Exception/DatabaseObjectExistsException.php index fb19f5bae..7e0ba0299 100644 --- a/doctrine/dbal/src/Exception/DatabaseObjectExistsException.php +++ b/doctrine/dbal/src/Exception/DatabaseObjectExistsException.php @@ -8,8 +8,6 @@ * A database object is considered any asset that can be created in a database * such as schemas, tables, views, sequences, triggers, constraints, indexes, * functions, stored procedures etc. - * - * @psalm-immutable */ class DatabaseObjectExistsException extends ServerException { diff --git a/doctrine/dbal/src/Exception/DatabaseObjectNotFoundException.php b/doctrine/dbal/src/Exception/DatabaseObjectNotFoundException.php index 2d3d78d99..3342bce8d 100644 --- a/doctrine/dbal/src/Exception/DatabaseObjectNotFoundException.php +++ b/doctrine/dbal/src/Exception/DatabaseObjectNotFoundException.php @@ -8,8 +8,6 @@ * A database object is considered any asset that can be created in a database * such as schemas, tables, views, sequences, triggers, constraints, indexes, * functions, stored procedures etc. - * - * @psalm-immutable */ class DatabaseObjectNotFoundException extends ServerException { diff --git a/doctrine/dbal/src/Exception/DatabaseRequired.php b/doctrine/dbal/src/Exception/DatabaseRequired.php index 49b7326cd..6889a5d23 100644 --- a/doctrine/dbal/src/Exception/DatabaseRequired.php +++ b/doctrine/dbal/src/Exception/DatabaseRequired.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ class DatabaseRequired extends Exception { public static function new(string $methodName): self diff --git a/doctrine/dbal/src/Exception/DeadlockException.php b/doctrine/dbal/src/Exception/DeadlockException.php index f36be908a..fd0550a56 100644 --- a/doctrine/dbal/src/Exception/DeadlockException.php +++ b/doctrine/dbal/src/Exception/DeadlockException.php @@ -4,8 +4,6 @@ /** * Exception for a deadlock error of a transaction detected in the driver. - * - * @psalm-immutable */ class DeadlockException extends ServerException implements RetryableException { diff --git a/doctrine/dbal/src/Exception/DriverException.php b/doctrine/dbal/src/Exception/DriverException.php index 8bba9dd87..559a40c29 100644 --- a/doctrine/dbal/src/Exception/DriverException.php +++ b/doctrine/dbal/src/Exception/DriverException.php @@ -10,8 +10,6 @@ /** * Base class for all errors detected in the driver. - * - * @psalm-immutable */ class DriverException extends Exception implements TheDriverException { diff --git a/doctrine/dbal/src/Exception/ForeignKeyConstraintViolationException.php b/doctrine/dbal/src/Exception/ForeignKeyConstraintViolationException.php index f1a612b21..48d736f9e 100644 --- a/doctrine/dbal/src/Exception/ForeignKeyConstraintViolationException.php +++ b/doctrine/dbal/src/Exception/ForeignKeyConstraintViolationException.php @@ -4,8 +4,6 @@ /** * Exception for a foreign key constraint violation detected in the driver. - * - * @psalm-immutable */ class ForeignKeyConstraintViolationException extends ConstraintViolationException { diff --git a/doctrine/dbal/src/Exception/InvalidArgumentException.php b/doctrine/dbal/src/Exception/InvalidArgumentException.php index 7f58510f0..044cecfec 100644 --- a/doctrine/dbal/src/Exception/InvalidArgumentException.php +++ b/doctrine/dbal/src/Exception/InvalidArgumentException.php @@ -6,8 +6,6 @@ /** * Exception to be thrown when invalid arguments are passed to any DBAL API - * - * @psalm-immutable */ class InvalidArgumentException extends Exception { diff --git a/doctrine/dbal/src/Exception/InvalidFieldNameException.php b/doctrine/dbal/src/Exception/InvalidFieldNameException.php index 234941bf6..d960feaf8 100644 --- a/doctrine/dbal/src/Exception/InvalidFieldNameException.php +++ b/doctrine/dbal/src/Exception/InvalidFieldNameException.php @@ -4,8 +4,6 @@ /** * Exception for an invalid specified field name in a statement detected in the driver. - * - * @psalm-immutable */ class InvalidFieldNameException extends ServerException { diff --git a/doctrine/dbal/src/Exception/InvalidLockMode.php b/doctrine/dbal/src/Exception/InvalidLockMode.php index f1780c459..9c38c77c2 100644 --- a/doctrine/dbal/src/Exception/InvalidLockMode.php +++ b/doctrine/dbal/src/Exception/InvalidLockMode.php @@ -6,7 +6,6 @@ use function sprintf; -/** @psalm-immutable */ class InvalidLockMode extends Exception { public static function fromLockMode(int $lockMode): self diff --git a/doctrine/dbal/src/Exception/LockWaitTimeoutException.php b/doctrine/dbal/src/Exception/LockWaitTimeoutException.php index 62aa10fca..bfc3a498a 100644 --- a/doctrine/dbal/src/Exception/LockWaitTimeoutException.php +++ b/doctrine/dbal/src/Exception/LockWaitTimeoutException.php @@ -4,8 +4,6 @@ /** * Exception for a lock wait timeout error of a transaction detected in the driver. - * - * @psalm-immutable */ class LockWaitTimeoutException extends ServerException implements RetryableException { diff --git a/doctrine/dbal/src/Exception/MalformedDsnException.php b/doctrine/dbal/src/Exception/MalformedDsnException.php index 01cd7c200..3f9b87443 100644 --- a/doctrine/dbal/src/Exception/MalformedDsnException.php +++ b/doctrine/dbal/src/Exception/MalformedDsnException.php @@ -4,7 +4,6 @@ use InvalidArgumentException; -/** @psalm-immutable */ class MalformedDsnException extends InvalidArgumentException { public static function new(): self diff --git a/doctrine/dbal/src/Exception/NoKeyValue.php b/doctrine/dbal/src/Exception/NoKeyValue.php index 545ade3ec..be5508a34 100644 --- a/doctrine/dbal/src/Exception/NoKeyValue.php +++ b/doctrine/dbal/src/Exception/NoKeyValue.php @@ -6,11 +6,7 @@ use function sprintf; -/** - * @internal - * - * @psalm-immutable - */ +/** @internal */ final class NoKeyValue extends Exception { public static function fromColumnCount(int $columnCount): self diff --git a/doctrine/dbal/src/Exception/NonUniqueFieldNameException.php b/doctrine/dbal/src/Exception/NonUniqueFieldNameException.php index 9ff662733..fd56f8969 100644 --- a/doctrine/dbal/src/Exception/NonUniqueFieldNameException.php +++ b/doctrine/dbal/src/Exception/NonUniqueFieldNameException.php @@ -4,8 +4,6 @@ /** * Exception for a non-unique/ambiguous specified field name in a statement detected in the driver. - * - * @psalm-immutable */ class NonUniqueFieldNameException extends ServerException { diff --git a/doctrine/dbal/src/Exception/NotNullConstraintViolationException.php b/doctrine/dbal/src/Exception/NotNullConstraintViolationException.php index 113b737bb..e327bc94d 100644 --- a/doctrine/dbal/src/Exception/NotNullConstraintViolationException.php +++ b/doctrine/dbal/src/Exception/NotNullConstraintViolationException.php @@ -4,8 +4,6 @@ /** * Exception for a NOT NULL constraint violation detected in the driver. - * - * @psalm-immutable */ class NotNullConstraintViolationException extends ConstraintViolationException { diff --git a/doctrine/dbal/src/Exception/ReadOnlyException.php b/doctrine/dbal/src/Exception/ReadOnlyException.php index 621363af9..a846f2501 100644 --- a/doctrine/dbal/src/Exception/ReadOnlyException.php +++ b/doctrine/dbal/src/Exception/ReadOnlyException.php @@ -4,8 +4,6 @@ /** * Exception for a write operation attempt on a read-only database element detected in the driver. - * - * @psalm-immutable */ class ReadOnlyException extends ServerException { diff --git a/doctrine/dbal/src/Exception/RetryableException.php b/doctrine/dbal/src/Exception/RetryableException.php index 79e325199..4cb94b100 100644 --- a/doctrine/dbal/src/Exception/RetryableException.php +++ b/doctrine/dbal/src/Exception/RetryableException.php @@ -6,8 +6,6 @@ /** * Marker interface for all exceptions where retrying the transaction makes sense. - * - * @psalm-immutable */ interface RetryableException extends Throwable { diff --git a/doctrine/dbal/src/Exception/SchemaDoesNotExist.php b/doctrine/dbal/src/Exception/SchemaDoesNotExist.php index de6fa5c00..13813838e 100644 --- a/doctrine/dbal/src/Exception/SchemaDoesNotExist.php +++ b/doctrine/dbal/src/Exception/SchemaDoesNotExist.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL\Exception; -/** @psalm-immutable */ class SchemaDoesNotExist extends DatabaseObjectNotFoundException { } diff --git a/doctrine/dbal/src/Exception/ServerException.php b/doctrine/dbal/src/Exception/ServerException.php index 194bc9cdd..c88c3863b 100644 --- a/doctrine/dbal/src/Exception/ServerException.php +++ b/doctrine/dbal/src/Exception/ServerException.php @@ -4,8 +4,6 @@ /** * Base class for all server related errors detected in the driver. - * - * @psalm-immutable */ class ServerException extends DriverException { diff --git a/doctrine/dbal/src/Exception/SyntaxErrorException.php b/doctrine/dbal/src/Exception/SyntaxErrorException.php index 2603ac274..0b413b719 100644 --- a/doctrine/dbal/src/Exception/SyntaxErrorException.php +++ b/doctrine/dbal/src/Exception/SyntaxErrorException.php @@ -4,8 +4,6 @@ /** * Exception for a syntax error in a statement detected in the driver. - * - * @psalm-immutable */ class SyntaxErrorException extends ServerException { diff --git a/doctrine/dbal/src/Exception/TableExistsException.php b/doctrine/dbal/src/Exception/TableExistsException.php index b6575a25d..ff0df89af 100644 --- a/doctrine/dbal/src/Exception/TableExistsException.php +++ b/doctrine/dbal/src/Exception/TableExistsException.php @@ -4,8 +4,6 @@ /** * Exception for an already existing table referenced in a statement detected in the driver. - * - * @psalm-immutable */ class TableExistsException extends DatabaseObjectExistsException { diff --git a/doctrine/dbal/src/Exception/TableNotFoundException.php b/doctrine/dbal/src/Exception/TableNotFoundException.php index 445a38b5a..aeaa0057d 100644 --- a/doctrine/dbal/src/Exception/TableNotFoundException.php +++ b/doctrine/dbal/src/Exception/TableNotFoundException.php @@ -4,8 +4,6 @@ /** * Exception for an unknown table referenced in a statement detected in the driver. - * - * @psalm-immutable */ class TableNotFoundException extends DatabaseObjectNotFoundException { diff --git a/doctrine/dbal/src/Exception/TransactionRolledBack.php b/doctrine/dbal/src/Exception/TransactionRolledBack.php new file mode 100644 index 000000000..c3605a468 --- /dev/null +++ b/doctrine/dbal/src/Exception/TransactionRolledBack.php @@ -0,0 +1,7 @@ + $createFlags + * @phpstan-param int-mask-of $createFlags * * @return list The list of SQL statements. * @@ -2226,7 +2226,7 @@ private function buildCreateTableSQL(Table $table, bool $createIndexes, bool $cr } /** - * @param list $tables + * @param Table[] $tables * * @return list * @@ -4564,7 +4564,7 @@ protected function createReservedKeywordsList(): KeywordList * @deprecated Implement {@see createReservedKeywordsList()} instead. * * @return string - * @psalm-return class-string + * @phpstan-return class-string * * @throws Exception If not supported on this platform. */ diff --git a/doctrine/dbal/src/Platforms/Keywords/KeywordList.php b/doctrine/dbal/src/Platforms/Keywords/KeywordList.php index 584277395..d8b4f4630 100644 --- a/doctrine/dbal/src/Platforms/Keywords/KeywordList.php +++ b/doctrine/dbal/src/Platforms/Keywords/KeywordList.php @@ -9,7 +9,7 @@ /** * Abstract interface for a SQL reserved keyword dictionary. * - * @psalm-consistent-constructor + * @phpstan-consistent-constructor */ abstract class KeywordList { diff --git a/doctrine/dbal/src/Platforms/OraclePlatform.php b/doctrine/dbal/src/Platforms/OraclePlatform.php index eae13ee73..1b68fd5fb 100644 --- a/doctrine/dbal/src/Platforms/OraclePlatform.php +++ b/doctrine/dbal/src/Platforms/OraclePlatform.php @@ -473,8 +473,6 @@ protected function _getCreateTableSQL($name, array $columns, array $options = [] * @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon. * * {@inheritDoc} - * - * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaOracleReader.html */ public function getListTableIndexesSQL($table, $database = null) { diff --git a/doctrine/dbal/src/Platforms/PostgreSQLPlatform.php b/doctrine/dbal/src/Platforms/PostgreSQLPlatform.php index b74720145..c01e92659 100644 --- a/doctrine/dbal/src/Platforms/PostgreSQLPlatform.php +++ b/doctrine/dbal/src/Platforms/PostgreSQLPlatform.php @@ -405,8 +405,6 @@ public function getListTableConstraintsSQL($table) * @deprecated The SQL used for schema introspection is an implementation detail and should not be relied upon. * * {@inheritDoc} - * - * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ public function getListTableIndexesSQL($table, $database = null) { diff --git a/doctrine/dbal/src/Platforms/SqlitePlatform.php b/doctrine/dbal/src/Platforms/SqlitePlatform.php index 48c692fdb..39ce5d90d 100644 --- a/doctrine/dbal/src/Platforms/SqlitePlatform.php +++ b/doctrine/dbal/src/Platforms/SqlitePlatform.php @@ -1025,7 +1025,7 @@ public function getCreateConstraintSQL(Constraint $constraint, $table) * {@inheritDoc} * * @param int|null $createFlags - * @psalm-param int-mask-of|null $createFlags + * @phpstan-param int-mask-of|null $createFlags */ public function getCreateTableSQL(Table $table, $createFlags = null) { diff --git a/doctrine/dbal/src/Portability/Converter.php b/doctrine/dbal/src/Portability/Converter.php index d0503977b..effbf986f 100644 --- a/doctrine/dbal/src/Portability/Converter.php +++ b/doctrine/dbal/src/Portability/Converter.php @@ -151,7 +151,7 @@ private static function convertEmptyStringToNull($value) * @param T $value * * @return T|string - * @psalm-return (T is string ? string : T) + * @phpstan-return (T is string ? string : T) * * @template T */ @@ -228,7 +228,7 @@ private function createConvert(?callable $function, callable $id): callable return /** * @param T $value * - * @psalm-return (T is false ? false : T) + * @phpstan-return (T is false ? false : T) * * @template T */ diff --git a/doctrine/dbal/src/Query.php b/doctrine/dbal/src/Query.php index bfc9b14e2..e4ab80e7c 100644 --- a/doctrine/dbal/src/Query.php +++ b/doctrine/dbal/src/Query.php @@ -8,8 +8,6 @@ /** * An SQL query together with its bound parameters. - * - * @psalm-immutable */ final class Query { @@ -35,8 +33,6 @@ final class Query /** * @param array $params * @param array $types - * - * @psalm-suppress ImpurePropertyAssignment */ public function __construct(string $sql, array $params, array $types) { diff --git a/doctrine/dbal/src/Query/Expression/CompositeExpression.php b/doctrine/dbal/src/Query/Expression/CompositeExpression.php index 4cad8ec1d..c241ff7f2 100644 --- a/doctrine/dbal/src/Query/Expression/CompositeExpression.php +++ b/doctrine/dbal/src/Query/Expression/CompositeExpression.php @@ -149,7 +149,7 @@ public function with($part, ...$parts): self * Retrieves the amount of expressions on composite expression. * * @return int - * @psalm-return int<0, max> + * @phpstan-return int<0, max> */ #[ReturnTypeWillChange] public function count() diff --git a/doctrine/dbal/src/Query/QueryBuilder.php b/doctrine/dbal/src/Query/QueryBuilder.php index 4c5d6b8d4..208579c93 100644 --- a/doctrine/dbal/src/Query/QueryBuilder.php +++ b/doctrine/dbal/src/Query/QueryBuilder.php @@ -113,14 +113,14 @@ class QueryBuilder /** * The type of query this is. Can be select, update or delete. * - * @psalm-var self::SELECT|self::DELETE|self::UPDATE|self::INSERT + * @phpstan-var self::SELECT|self::DELETE|self::UPDATE|self::INSERT */ private int $type = self::SELECT; /** * The state of the query object. Can be dirty or clean. * - * @psalm-var self::STATE_* + * @phpstan-var self::STATE_* */ private int $state = self::STATE_CLEAN; @@ -219,7 +219,7 @@ public function getConnection() * @deprecated The builder state is an internal concern. * * @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN. - * @psalm-return self::STATE_* + * @phpstan-return self::STATE_* */ public function getState() { diff --git a/doctrine/dbal/src/Query/QueryException.php b/doctrine/dbal/src/Query/QueryException.php index 90d1f47d9..bfb5eafc3 100644 --- a/doctrine/dbal/src/Query/QueryException.php +++ b/doctrine/dbal/src/Query/QueryException.php @@ -6,7 +6,6 @@ use function implode; -/** @psalm-immutable */ class QueryException extends Exception { /** diff --git a/doctrine/dbal/src/Result.php b/doctrine/dbal/src/Result.php index 92235d064..f63b07f07 100644 --- a/doctrine/dbal/src/Result.php +++ b/doctrine/dbal/src/Result.php @@ -264,7 +264,7 @@ private function ensureHasKeyValue(): void * * @deprecated Use {@see fetchNumeric()}, {@see fetchAssociative()} or {@see fetchOne()} instead. * - * @psalm-param FetchMode::* $mode + * @phpstan-param FetchMode::* $mode * * @return mixed * @@ -303,7 +303,7 @@ public function fetch(int $mode = FetchMode::ASSOCIATIVE) * * @deprecated Use {@see fetchAllNumeric()}, {@see fetchAllAssociative()} or {@see fetchFirstColumn()} instead. * - * @psalm-param FetchMode::* $mode + * @phpstan-param FetchMode::* $mode * * @return list * diff --git a/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php b/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php index 2e392e661..74579b3e0 100644 --- a/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php +++ b/doctrine/dbal/src/SQL/Builder/CreateSchemaObjectsSQLBuilder.php @@ -34,7 +34,7 @@ public function buildSQL(Schema $schema): array } /** - * @param list $namespaces + * @param string[] $namespaces * * @return list * @@ -54,7 +54,7 @@ private function buildNamespaceStatements(array $namespaces): array } /** - * @param list
$tables + * @param Table[] $tables * * @return list * @@ -66,7 +66,7 @@ private function buildTableStatements(array $tables): array } /** - * @param list $sequences + * @param Sequence[] $sequences * * @return list * diff --git a/doctrine/dbal/src/Schema/Comparator.php b/doctrine/dbal/src/Schema/Comparator.php index 28e7f2f73..8114ec5e2 100644 --- a/doctrine/dbal/src/Schema/Comparator.php +++ b/doctrine/dbal/src/Schema/Comparator.php @@ -636,7 +636,7 @@ public function diffColumn(Column $column1, Column $column2) // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation. if ( ($properties1['default'] === null) !== ($properties2['default'] === null) - || $properties1['default'] != $properties2['default'] + || $properties1['default'] != $properties2['default'] // @phpstan-ignore notEqual.notAllowed ) { $changedProperties[] = 'default'; } diff --git a/doctrine/dbal/src/Schema/Exception/ColumnAlreadyExists.php b/doctrine/dbal/src/Schema/Exception/ColumnAlreadyExists.php index cc7acea03..a0d62d20d 100644 --- a/doctrine/dbal/src/Schema/Exception/ColumnAlreadyExists.php +++ b/doctrine/dbal/src/Schema/Exception/ColumnAlreadyExists.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class ColumnAlreadyExists extends SchemaException { public static function new(string $tableName, string $columnName): self diff --git a/doctrine/dbal/src/Schema/Exception/ColumnDoesNotExist.php b/doctrine/dbal/src/Schema/Exception/ColumnDoesNotExist.php index c9036a07c..7c4bb633c 100644 --- a/doctrine/dbal/src/Schema/Exception/ColumnDoesNotExist.php +++ b/doctrine/dbal/src/Schema/Exception/ColumnDoesNotExist.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class ColumnDoesNotExist extends SchemaException { public static function new(string $columnName, string $table): self diff --git a/doctrine/dbal/src/Schema/Exception/ForeignKeyDoesNotExist.php b/doctrine/dbal/src/Schema/Exception/ForeignKeyDoesNotExist.php index bf57cd4ff..4833de5c0 100644 --- a/doctrine/dbal/src/Schema/Exception/ForeignKeyDoesNotExist.php +++ b/doctrine/dbal/src/Schema/Exception/ForeignKeyDoesNotExist.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class ForeignKeyDoesNotExist extends SchemaException { public static function new(string $foreignKeyName, string $table): self diff --git a/doctrine/dbal/src/Schema/Exception/IndexAlreadyExists.php b/doctrine/dbal/src/Schema/Exception/IndexAlreadyExists.php index 25facb58a..292bf81e4 100644 --- a/doctrine/dbal/src/Schema/Exception/IndexAlreadyExists.php +++ b/doctrine/dbal/src/Schema/Exception/IndexAlreadyExists.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class IndexAlreadyExists extends SchemaException { public static function new(string $indexName, string $table): self diff --git a/doctrine/dbal/src/Schema/Exception/IndexDoesNotExist.php b/doctrine/dbal/src/Schema/Exception/IndexDoesNotExist.php index 9f4024185..526819726 100644 --- a/doctrine/dbal/src/Schema/Exception/IndexDoesNotExist.php +++ b/doctrine/dbal/src/Schema/Exception/IndexDoesNotExist.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class IndexDoesNotExist extends SchemaException { public static function new(string $indexName, string $table): self diff --git a/doctrine/dbal/src/Schema/Exception/IndexNameInvalid.php b/doctrine/dbal/src/Schema/Exception/IndexNameInvalid.php index 5230f506e..d69b7a930 100644 --- a/doctrine/dbal/src/Schema/Exception/IndexNameInvalid.php +++ b/doctrine/dbal/src/Schema/Exception/IndexNameInvalid.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class IndexNameInvalid extends SchemaException { public static function new(string $indexName): self diff --git a/doctrine/dbal/src/Schema/Exception/InvalidTableName.php b/doctrine/dbal/src/Schema/Exception/InvalidTableName.php index 50e2d3af9..763e920f6 100644 --- a/doctrine/dbal/src/Schema/Exception/InvalidTableName.php +++ b/doctrine/dbal/src/Schema/Exception/InvalidTableName.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class InvalidTableName extends SchemaException { public static function new(string $tableName): self diff --git a/doctrine/dbal/src/Schema/Exception/NamedForeignKeyRequired.php b/doctrine/dbal/src/Schema/Exception/NamedForeignKeyRequired.php index 92d237e7a..453286136 100644 --- a/doctrine/dbal/src/Schema/Exception/NamedForeignKeyRequired.php +++ b/doctrine/dbal/src/Schema/Exception/NamedForeignKeyRequired.php @@ -11,7 +11,6 @@ use function implode; use function sprintf; -/** @psalm-immutable */ final class NamedForeignKeyRequired extends SchemaException { public static function new(Table $localTable, ForeignKeyConstraint $foreignKey): self diff --git a/doctrine/dbal/src/Schema/Exception/NamespaceAlreadyExists.php b/doctrine/dbal/src/Schema/Exception/NamespaceAlreadyExists.php index 008bd5f0e..527e196ef 100644 --- a/doctrine/dbal/src/Schema/Exception/NamespaceAlreadyExists.php +++ b/doctrine/dbal/src/Schema/Exception/NamespaceAlreadyExists.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class NamespaceAlreadyExists extends SchemaException { public static function new(string $namespaceName): self diff --git a/doctrine/dbal/src/Schema/Exception/SequenceAlreadyExists.php b/doctrine/dbal/src/Schema/Exception/SequenceAlreadyExists.php index d719c6a06..206220ef7 100644 --- a/doctrine/dbal/src/Schema/Exception/SequenceAlreadyExists.php +++ b/doctrine/dbal/src/Schema/Exception/SequenceAlreadyExists.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class SequenceAlreadyExists extends SchemaException { public static function new(string $sequenceName): self diff --git a/doctrine/dbal/src/Schema/Exception/SequenceDoesNotExist.php b/doctrine/dbal/src/Schema/Exception/SequenceDoesNotExist.php index 3f948835c..6b4912d52 100644 --- a/doctrine/dbal/src/Schema/Exception/SequenceDoesNotExist.php +++ b/doctrine/dbal/src/Schema/Exception/SequenceDoesNotExist.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class SequenceDoesNotExist extends SchemaException { public static function new(string $sequenceName): self diff --git a/doctrine/dbal/src/Schema/Exception/TableAlreadyExists.php b/doctrine/dbal/src/Schema/Exception/TableAlreadyExists.php index d7b235937..c5a64f6b8 100644 --- a/doctrine/dbal/src/Schema/Exception/TableAlreadyExists.php +++ b/doctrine/dbal/src/Schema/Exception/TableAlreadyExists.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class TableAlreadyExists extends SchemaException { public static function new(string $tableName): self diff --git a/doctrine/dbal/src/Schema/Exception/TableDoesNotExist.php b/doctrine/dbal/src/Schema/Exception/TableDoesNotExist.php index 7c6dda9ab..47c5f0eab 100644 --- a/doctrine/dbal/src/Schema/Exception/TableDoesNotExist.php +++ b/doctrine/dbal/src/Schema/Exception/TableDoesNotExist.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class TableDoesNotExist extends SchemaException { public static function new(string $tableName): self diff --git a/doctrine/dbal/src/Schema/Exception/UniqueConstraintDoesNotExist.php b/doctrine/dbal/src/Schema/Exception/UniqueConstraintDoesNotExist.php index dad6116c6..0ce19f756 100644 --- a/doctrine/dbal/src/Schema/Exception/UniqueConstraintDoesNotExist.php +++ b/doctrine/dbal/src/Schema/Exception/UniqueConstraintDoesNotExist.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class UniqueConstraintDoesNotExist extends SchemaException { public static function new(string $constraintName, string $table): self diff --git a/doctrine/dbal/src/Schema/Exception/UnknownColumnOption.php b/doctrine/dbal/src/Schema/Exception/UnknownColumnOption.php index 7a7c6f87a..d128e224f 100644 --- a/doctrine/dbal/src/Schema/Exception/UnknownColumnOption.php +++ b/doctrine/dbal/src/Schema/Exception/UnknownColumnOption.php @@ -8,7 +8,6 @@ use function sprintf; -/** @psalm-immutable */ final class UnknownColumnOption extends SchemaException { public static function new(string $name): self diff --git a/doctrine/dbal/src/Schema/OracleSchemaManager.php b/doctrine/dbal/src/Schema/OracleSchemaManager.php index 073752214..3608e0566 100644 --- a/doctrine/dbal/src/Schema/OracleSchemaManager.php +++ b/doctrine/dbal/src/Schema/OracleSchemaManager.php @@ -107,8 +107,6 @@ protected function _getPortableTableDefinition($table) /** * {@inheritDoc} - * - * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { diff --git a/doctrine/dbal/src/Schema/PostgreSQLSchemaManager.php b/doctrine/dbal/src/Schema/PostgreSQLSchemaManager.php index 3ad313eba..1716249fc 100644 --- a/doctrine/dbal/src/Schema/PostgreSQLSchemaManager.php +++ b/doctrine/dbal/src/Schema/PostgreSQLSchemaManager.php @@ -287,8 +287,6 @@ protected function _getPortableTableDefinition($table) /** * {@inheritDoc} - * - * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { diff --git a/doctrine/dbal/src/Schema/SchemaException.php b/doctrine/dbal/src/Schema/SchemaException.php index 4ec091f8d..24a9dd346 100644 --- a/doctrine/dbal/src/Schema/SchemaException.php +++ b/doctrine/dbal/src/Schema/SchemaException.php @@ -19,7 +19,6 @@ use function sprintf; -/** @psalm-immutable */ class SchemaException extends Exception { /** @deprecated Use {@see TableDoesNotExist} instead. */ diff --git a/doctrine/dbal/src/Schema/SqliteSchemaManager.php b/doctrine/dbal/src/Schema/SqliteSchemaManager.php index 0419e934b..3b464f21a 100644 --- a/doctrine/dbal/src/Schema/SqliteSchemaManager.php +++ b/doctrine/dbal/src/Schema/SqliteSchemaManager.php @@ -222,8 +222,6 @@ protected function _getPortableTableDefinition($table) /** * {@inheritDoc} - * - * @link http://ezcomponents.org/docs/api/trunk/DatabaseSchema/ezcDbSchemaPgsqlReader.html */ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { @@ -510,9 +508,8 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey): Fore private function parseColumnCollationFromSQL(string $column, string $sql): ?string { - $pattern = '{(?:\W' . preg_quote($column) . '\W|\W' - . preg_quote($this->_platform->quoteSingleIdentifier($column)) - . '\W)[^,(]+(?:\([^()]+\)[^,]*)?(?:(?:DEFAULT|CHECK)\s*(?:\(.*?\))?[^,]*)*COLLATE\s+["\']?([^\s,"\')]+)}is'; + $pattern = '{' . $this->buildIdentifierPattern($column) + . '[^,(]+(?:\([^()]+\)[^,]*)?(?:(?:DEFAULT|CHECK)\s*(?:\(.*?\))?[^,]*)*COLLATE\s+["\']?([^\s,"\')]+)}is'; if (preg_match($pattern, $sql, $match) !== 1) { return null; @@ -524,9 +521,7 @@ private function parseColumnCollationFromSQL(string $column, string $sql): ?stri private function parseTableCommentFromSQL(string $table, string $sql): ?string { $pattern = '/\s* # Allow whitespace characters at start of line -CREATE\sTABLE # Match "CREATE TABLE" -(?:\W"' . preg_quote($this->_platform->quoteSingleIdentifier($table), '/') . '"\W|\W' . preg_quote($table, '/') - . '\W) # Match table name (quoted and unquoted) +CREATE\sTABLE' . $this->buildIdentifierPattern($table) . ' ( # Start capture (?:\s*--[^\n]*\n?)+ # Capture anything that starts with whitespaces followed by -- until the end of the line(s) )/ix'; @@ -542,8 +537,8 @@ private function parseTableCommentFromSQL(string $table, string $sql): ?string private function parseColumnCommentFromSQL(string $column, string $sql): ?string { - $pattern = '{[\s(,](?:\W' . preg_quote($this->_platform->quoteSingleIdentifier($column)) - . '\W|\W' . preg_quote($column) . '\W)(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i'; + $pattern = '{[\s(,]' . $this->buildIdentifierPattern($column) + . '(?:\([^)]*?\)|[^,(])*?,?((?:(?!\n))(?:\s*--[^\n]*\n?)+)}i'; if (preg_match($pattern, $sql, $match) !== 1) { return null; @@ -554,6 +549,22 @@ private function parseColumnCommentFromSQL(string $column, string $sql): ?string return $comment === '' ? null : $comment; } + /** + * Returns a regular expression pattern that matches the given unquoted or quoted identifier. + */ + private function buildIdentifierPattern(string $identifier): string + { + return '(?:' . implode('|', array_map( + static function (string $sql): string { + return '\W' . preg_quote($sql, '/') . '\W'; + }, + [ + $identifier, + $this->_platform->quoteSingleIdentifier($identifier), + ], + )) . ')'; + } + /** @throws Exception */ private function getCreateTableSQL(string $table): string { diff --git a/doctrine/dbal/src/Tools/DsnParser.php b/doctrine/dbal/src/Tools/DsnParser.php index 4ac0484d1..753701491 100644 --- a/doctrine/dbal/src/Tools/DsnParser.php +++ b/doctrine/dbal/src/Tools/DsnParser.php @@ -19,7 +19,7 @@ use function strpos; use function substr; -/** @psalm-import-type Params from DriverManager */ +/** @phpstan-import-type Params from DriverManager */ final class DsnParser { /** @var array> */ @@ -32,7 +32,7 @@ public function __construct(array $schemeMapping = []) } /** - * @psalm-return Params + * @phpstan-return Params * * @throws MalformedDsnException */ diff --git a/doctrine/dbal/src/Types/ConversionException.php b/doctrine/dbal/src/Types/ConversionException.php index 154b06d3e..2401aaeb9 100644 --- a/doctrine/dbal/src/Types/ConversionException.php +++ b/doctrine/dbal/src/Types/ConversionException.php @@ -19,8 +19,6 @@ /** * Conversion Exception is thrown when the database to PHP conversion fails. - * - * @psalm-immutable */ class ConversionException extends Exception { diff --git a/doctrine/dbal/src/Types/DateTimeTzImmutableType.php b/doctrine/dbal/src/Types/DateTimeTzImmutableType.php index e700f68d4..70f2c78b6 100644 --- a/doctrine/dbal/src/Types/DateTimeTzImmutableType.php +++ b/doctrine/dbal/src/Types/DateTimeTzImmutableType.php @@ -22,7 +22,7 @@ public function getName() /** * {@inheritDoc} * - * @psalm-param T $value + * @phpstan-param T $value * * @return (T is null ? null : string) * diff --git a/doctrine/dbal/src/Types/DateType.php b/doctrine/dbal/src/Types/DateType.php index 842e8bd09..86a5ab1ec 100644 --- a/doctrine/dbal/src/Types/DateType.php +++ b/doctrine/dbal/src/Types/DateType.php @@ -34,7 +34,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform) /** * {@inheritDoc} * - * @psalm-param T $value + * @phpstan-param T $value * * @return (T is null ? null : string) * diff --git a/doctrine/event-manager/src/EventArgs.php b/doctrine/event-manager/src/EventArgs.php index 4795ba6be..eea3d8a0a 100644 --- a/doctrine/event-manager/src/EventArgs.php +++ b/doctrine/event-manager/src/EventArgs.php @@ -15,10 +15,8 @@ class EventArgs { /** * Single instance of EventArgs. - * - * @var EventArgs|null */ - private static $_emptyEventArgsInstance; + private static EventArgs|null $emptyEventArgsInstance = null; /** * Gets the single, empty and immutable EventArgs instance. @@ -31,15 +29,9 @@ class EventArgs * * @link https://msdn.microsoft.com/en-us/library/system.eventargs.aspx * @see EventManager::dispatchEvent - * - * @return EventArgs */ - public static function getEmptyInstance() + public static function getEmptyInstance(): EventArgs { - if (! self::$_emptyEventArgsInstance) { - self::$_emptyEventArgsInstance = new EventArgs(); - } - - return self::$_emptyEventArgsInstance; + return self::$emptyEventArgsInstance ??= new EventArgs(); } } diff --git a/doctrine/event-manager/src/EventManager.php b/doctrine/event-manager/src/EventManager.php index 6d841be27..86f5e4536 100644 --- a/doctrine/event-manager/src/EventManager.php +++ b/doctrine/event-manager/src/EventManager.php @@ -1,8 +1,8 @@ */ - private $listeners = []; + private array $listeners = []; /** * Dispatches an event to all registered listeners. @@ -28,16 +28,14 @@ class EventManager * the name of the method that is invoked on listeners. * @param EventArgs|null $eventArgs The event arguments to pass to the event handlers/listeners. * If not supplied, the single empty EventArgs instance is used. - * - * @return void */ - public function dispatchEvent($eventName, ?EventArgs $eventArgs = null) + public function dispatchEvent(string $eventName, EventArgs|null $eventArgs = null): void { if (! isset($this->listeners[$eventName])) { return; } - $eventArgs = $eventArgs ?? EventArgs::getEmptyInstance(); + $eventArgs ??= EventArgs::getEmptyInstance(); foreach ($this->listeners[$eventName] as $listener) { $listener->$eventName($eventArgs); @@ -47,24 +45,12 @@ public function dispatchEvent($eventName, ?EventArgs $eventArgs = null) /** * Gets the listeners of a specific event. * - * @param string|null $event The name of the event. + * @param string $event The name of the event. * - * @return object[]|array The event listeners for the specified event, or all event listeners. - * @psalm-return ($event is null ? array : object[]) + * @return object[] */ - public function getListeners($event = null) + public function getListeners(string $event): array { - if ($event === null) { - Deprecation::trigger( - 'doctrine/event-manager', - 'https://github.com/doctrine/event-manager/pull/50', - 'Calling %s without an event name is deprecated. Call getAllListeners() instead.', - __METHOD__ - ); - - return $this->getAllListeners(); - } - return $this->listeners[$event] ?? []; } @@ -80,12 +66,8 @@ public function getAllListeners(): array /** * Checks whether an event has any registered listeners. - * - * @param string $event - * - * @return bool TRUE if the specified event has any listeners, FALSE otherwise. */ - public function hasListeners($event) + public function hasListeners(string $event): bool { return ! empty($this->listeners[$event]); } @@ -95,10 +77,8 @@ public function hasListeners($event) * * @param string|string[] $events The event(s) to listen on. * @param object $listener The listener object. - * - * @return void */ - public function addEventListener($events, $listener) + public function addEventListener(string|array $events, object $listener): void { // Picks the hash code related to that listener $hash = spl_object_hash($listener); @@ -114,11 +94,8 @@ public function addEventListener($events, $listener) * Removes an event listener from the specified events. * * @param string|string[] $events - * @param object $listener - * - * @return void */ - public function removeEventListener($events, $listener) + public function removeEventListener(string|array $events, object $listener): void { // Picks the hash code related to that listener $hash = spl_object_hash($listener); @@ -129,27 +106,23 @@ public function removeEventListener($events, $listener) } /** - * Adds an EventSubscriber. The subscriber is asked for all the events it is - * interested in and added as a listener for these events. + * Adds an EventSubscriber. * - * @param EventSubscriber $subscriber The subscriber. - * - * @return void + * The subscriber is asked for all the events it is interested in and added + * as a listener for these events. */ - public function addEventSubscriber(EventSubscriber $subscriber) + public function addEventSubscriber(EventSubscriber $subscriber): void { $this->addEventListener($subscriber->getSubscribedEvents(), $subscriber); } /** - * Removes an EventSubscriber. The subscriber is asked for all the events it is - * interested in and removed as a listener for these events. - * - * @param EventSubscriber $subscriber The subscriber. + * Removes an EventSubscriber. * - * @return void + * The subscriber is asked for all the events it is interested in and removed + * as a listener for these events. */ - public function removeEventSubscriber(EventSubscriber $subscriber) + public function removeEventSubscriber(EventSubscriber $subscriber): void { $this->removeEventListener($subscriber->getSubscribedEvents(), $subscriber); }