Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate QueryBuilder APIs exposing its internal state #5551

Merged
merged 1 commit into from Jul 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions UPGRADE.md
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions psalm.xml.dist
Expand Up @@ -111,6 +111,11 @@
<file name="src/Types/ObjectType.php"/>
<file name="src/Types/Type.php"/>
<file name="tests/Schema/ComparatorTest.php"/>
<!--
TODO: remove in 4.0.0
-->
<file name="src/Query/QueryBuilder.php"/>
<file name="tests/Query/QueryBuilderTest.php"/>
</errorLevel>
</DeprecatedConstant>
<DeprecatedInterface>
Expand Down Expand Up @@ -389,6 +394,11 @@
-->
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getIndexFieldDeclarationListSQL"/>
<referencedMethod name="Doctrine\DBAL\Platforms\AbstractPlatform::getCustomTypeDeclarationSQL"/>
<!--
TODO: remove in 4.0.0
-->
<referencedMethod name="Doctrine\DBAL\Query\QueryBuilder::getState"/>
<referencedMethod name="Doctrine\DBAL\Query\QueryBuilder::getType"/>
</errorLevel>
</DeprecatedMethod>
<DeprecatedProperty>
Expand Down
41 changes: 37 additions & 4 deletions src/Query/QueryBuilder.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down