From b63901b6334587b29330d8042efc6fb185202f93 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Fri, 2 Apr 2021 16:32:26 +0200 Subject: [PATCH] Add missing runtime deprecations related to FC Result API (#4529, #4571) --- UPGRADE.md | 8 ++++++++ .../DBAL/ForwardCompatibility/Result.php | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 2ea6c38351e..587e1138151 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,3 +1,11 @@ +Note about upgrading: Doctrine uses static and runtime mechanisms to raise +awareness about deprecated code. + +- Use of `@deprecated` docblock that is detected by IDEs (like PHPStorm) or + Static Analysis tools (like Psalm, phpstan) +- Use of our low-overhead runtime deprecation API, details: + https://github.com/doctrine/deprecations/ + # Upgrade to 2.12 ## Deprecated non-zero based positional parameter keys diff --git a/lib/Doctrine/DBAL/ForwardCompatibility/Result.php b/lib/Doctrine/DBAL/ForwardCompatibility/Result.php index e46fffa3f86..bb3f63ac6d3 100644 --- a/lib/Doctrine/DBAL/ForwardCompatibility/Result.php +++ b/lib/Doctrine/DBAL/ForwardCompatibility/Result.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\NoKeyValue; use Doctrine\DBAL\Result as BaseResult; +use Doctrine\Deprecations\Deprecation; use IteratorAggregate; use PDO; use Traversable; @@ -70,6 +71,12 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) */ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Result::fetch() is deprecated, use Result::fetchNumeric(), fetchAssociative() or fetchOne() instead.' + ); + return $this->stmt->fetch($fetchMode, $cursorOrientation, $cursorOffset); } @@ -80,6 +87,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Result::fetchAll() is deprecated, use Result::fetchAllNumeric(), fetchAllAssociative() or ' . + 'fetchFirstColumn() instead.' + ); + return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs); } @@ -90,6 +104,12 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchColumn($columnIndex = 0) { + Deprecation::triggerIfCalledFromOutside( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/4019', + 'Result::fetchColumn() is deprecated, use Result::fetchOne() instead.' + ); + return $this->stmt->fetchColumn($columnIndex); }