From 99c16288065ad3fff0aeeac56332345dbb71a0b1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 30 Jul 2022 10:32:10 -0700 Subject: [PATCH] Deprecate QueryBuilder APIs exposing its internal state --- UPGRADE.md | 15 ++++++++++++++ psalm.xml.dist | 10 ++++++++++ src/Query/QueryBuilder.php | 41 ++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index d0a0dadd564..73d189c148c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -8,6 +8,21 @@ awareness about deprecated code. # Upgrade to 3.4 +## Deprecated `QueryBuilder` methods and constants. + +1. The `QueryBuilder::getState()` method has been deprecated as the builder state is an internal concern. +2. Relying on the type of the query being built is deprecated by using `QueryBuilder::getType()` has been deprecated. + If necessary, track the type of the query being built outside of the builder. + +The following `QueryBuilder` constants related to the above methods have been deprecated: + +1. `SELECT`, +2. `DELETE`, +3. `UPDATE`, +4. `INSERT`, +5. `STATE_DIRTY`, +6. `STATE_CLEAN`. + ## Marked `Connection::ARRAY_PARAM_OFFSET` as internal. The `Connection::ARRAY_PARAM_OFFSET` constant has been marked as internal. It will be removed in 4.0. diff --git a/psalm.xml.dist b/psalm.xml.dist index 7a987df013d..6fcee4db4dd 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -111,6 +111,11 @@ + + + @@ -389,6 +394,11 @@ --> + + + diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index fa0b49a5cc6..9d134e82009 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -37,18 +37,34 @@ */ class QueryBuilder { - /* - * The query types. + /** + * @deprecated */ public const SELECT = 0; + + /** + * @deprecated + */ public const DELETE = 1; + + /** + * @deprecated + */ public const UPDATE = 2; + + /** + * @deprecated + */ public const INSERT = 3; - /* - * The builder states. + /** + * @deprecated */ public const STATE_DIRTY = 0; + + /** + * @deprecated + */ public const STATE_CLEAN = 1; /** @@ -157,10 +173,19 @@ public function expr() /** * Gets the type of the currently built query. * + * @deprecated If necessary, track the type of the query being built outside of the builder. + * * @return int */ public function getType() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5551', + 'Relying on the type of the query being built is deprecated.' + . ' If necessary, track the type of the query being built outside of the builder.' + ); + return $this->type; } @@ -177,10 +202,18 @@ public function getConnection() /** * Gets the state of this query builder instance. * + * @deprecated The builder state is an internal concern. + * * @return int Either QueryBuilder::STATE_DIRTY or QueryBuilder::STATE_CLEAN. */ public function getState() { + Deprecation::trigger( + 'doctrine/dbal', + 'https://github.com/doctrine/dbal/pull/5551', + 'Relying on the query builder state is deprecated as it is an internal concern.' + ); + return $this->state; }