diff --git a/UPGRADE.md b/UPGRADE.md index 712c418d973..d34f3cb1764 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,11 @@ awareness about deprecated code. # Upgrade to 5.0 +## BC BREAK: Add `Result::getColumnName()` + +A new method `getColumnName()` has been added to the `Result` interface and must be implemented by +all drivers and middleware. + ## BC BREAK: Removed support for MariaDB 10.4 and MySQL 5.7 * Upgrade to MariaDB 10.5 or later. diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 164caf3ae56..acdc6bceaf2 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -108,10 +108,6 @@ parameters: - message: '#^Parameter \#2 \$callback of function array_reduce expects callable\(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null, callable\(T\)\: T\)\: \(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null\), Closure\(callable\|null, callable\)\: \(callable\(T\)\: T\) given\.$#' path: src/Portability/Converter.php - - # Type check for legacy implementations of the Result interface - # TODO: remove in 5.0.0 - - '~^Call to function method_exists\(\) with Doctrine\\DBAL\\Driver\\Result and ''getColumnName'' will always evaluate to true\.$~' includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon diff --git a/src/Driver/Middleware/AbstractResultMiddleware.php b/src/Driver/Middleware/AbstractResultMiddleware.php index f335c216e04..308cd2e88ed 100644 --- a/src/Driver/Middleware/AbstractResultMiddleware.php +++ b/src/Driver/Middleware/AbstractResultMiddleware.php @@ -5,11 +5,6 @@ namespace Doctrine\DBAL\Driver\Middleware; use Doctrine\DBAL\Driver\Result; -use LogicException; - -use function get_debug_type; -use function method_exists; -use function sprintf; abstract class AbstractResultMiddleware implements Result { @@ -68,13 +63,6 @@ public function columnCount(): int public function getColumnName(int $index): string { - if (! method_exists($this->wrappedResult, 'getColumnName')) { - throw new LogicException(sprintf( - 'The driver result %s does not support accessing the column name.', - get_debug_type($this->wrappedResult), - )); - } - return $this->wrappedResult->getColumnName($index); } diff --git a/src/Driver/Result.php b/src/Driver/Result.php index c26e38cb8a4..b7826cf5437 100644 --- a/src/Driver/Result.php +++ b/src/Driver/Result.php @@ -6,8 +6,6 @@ /** * Driver-level statement execution result. - * - * @method string getColumnName(int $index) */ interface Result { @@ -88,6 +86,11 @@ public function rowCount(): int|string; */ public function columnCount(): int; + /** + * Returns the name of the column in the result set for the given 0-based index. + */ + public function getColumnName(int $index): string; + /** * Discards the non-fetched portion of the result, enabling the originating statement to be executed again. */ diff --git a/src/Result.php b/src/Result.php index 12d38e0b449..afcb90a2960 100644 --- a/src/Result.php +++ b/src/Result.php @@ -7,15 +7,11 @@ use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Driver\Result as DriverResult; use Doctrine\DBAL\Exception\NoKeyValue; -use LogicException; use Traversable; use function array_shift; use function assert; use function count; -use function get_debug_type; -use function method_exists; -use function sprintf; class Result { @@ -266,13 +262,6 @@ public function columnCount(): int */ public function getColumnName(int $index): string { - if (! method_exists($this->result, 'getColumnName')) { - throw new LogicException(sprintf( - 'The driver result %s does not support accessing the column name.', - get_debug_type($this->result), - )); - } - try { return $this->result->getColumnName($index); } catch (DriverException $e) {