Skip to content

Commit 77da03e

Browse files
authored
Merge pull request #2271 from antograssiot/queryJoinParser-cleanup
Deprecate dead code in QueryJoinParser and remove internal usage
2 parents 647cafe + 6a0c10a commit 77da03e

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/Bridge/Doctrine/Orm/Util/QueryChecker.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, Manage
9595

9696
$orderByAliases = [];
9797
foreach ($orderByParts as $orderBy) {
98-
$parts = QueryJoinParser::getOrderByParts($orderBy);
98+
$parts = $orderBy->getParts();
9999

100100
foreach ($parts as $part) {
101101
$pos = strpos($part, '.');
@@ -111,12 +111,12 @@ public static function hasOrderByOnToManyJoin(QueryBuilder $queryBuilder, Manage
111111

112112
foreach ($joinParts as $joins) {
113113
foreach ($joins as $join) {
114-
$alias = QueryJoinParser::getJoinAlias($join);
114+
$alias = $join->getAlias();
115115

116116
if (!isset($orderByAliases[$alias])) {
117117
continue;
118118
}
119-
$relationship = QueryJoinParser::getJoinRelationship($join);
119+
$relationship = $join->getJoin();
120120

121121
if (false !== strpos($relationship, '.')) {
122122
/*

src/Bridge/Doctrine/Orm/Util/QueryJoinParser.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder
4848
$aliasMap[$rootAlias] = 'root';
4949

5050
foreach ($joins as $join) {
51-
$alias = self::getJoinAlias($join);
52-
$relationship = self::getJoinRelationship($join);
51+
$alias = $join->getAlias();
52+
$relationship = $join->getJoin();
5353

5454
$pos = strpos($relationship, '.');
5555

@@ -100,6 +100,8 @@ public static function getClassMetadataFromJoinAlias(string $alias, QueryBuilder
100100
*/
101101
public static function getJoinRelationship(Join $join): string
102102
{
103+
@trigger_error(sprintf('The use of "%s::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getJoin()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
104+
103105
return $join->getJoin();
104106
}
105107

@@ -108,17 +110,20 @@ public static function getJoinRelationship(Join $join): string
108110
*/
109111
public static function getJoinAlias(Join $join): string
110112
{
113+
@trigger_error(sprintf('The use of "%s::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getAlias()" directly instead.', __CLASS__, Join::class), E_USER_DEPRECATED);
114+
111115
return $join->getAlias();
112116
}
113117

114118
/**
115119
* Gets the parts from an OrderBy expression.
116120
*
117-
*
118121
* @return string[]
119122
*/
120123
public static function getOrderByParts(OrderBy $orderBy): array
121124
{
125+
@trigger_error(sprintf('The use of "%s::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "%s::getParts()" directly instead.', __CLASS__, OrderBy::class), E_USER_DEPRECATED);
126+
122127
return $orderBy->getParts();
123128
}
124129
}

tests/Bridge/Doctrine/Orm/Util/QueryJoinParserTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,30 +43,50 @@ public function testGetClassMetadataFromJoinAlias()
4343
$this->assertEquals($metadata, $classMetadata->reveal());
4444
}
4545

46+
/**
47+
* @group legacy
48+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getJoin()" directly instead.
49+
*/
4650
public function testGetJoinRelationshipWithJoin()
4751
{
4852
$join = new Join('INNER_JOIN', 'a_1.relatedDummy', 'a_1', null, 'a_1.name = r.name');
4953
$this->assertEquals('a_1.relatedDummy', QueryJoinParser::getJoinRelationship($join));
5054
}
5155

56+
/**
57+
* @group legacy
58+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinRelationship()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getJoin()" directly instead.
59+
*/
5260
public function testGetJoinRelationshipWithClassJoin()
5361
{
5462
$join = new Join('INNER_JOIN', RelatedDummy::class, 'a_1', null, 'a_1.name = r.name');
5563
$this->assertEquals(RelatedDummy::class, QueryJoinParser::getJoinRelationship($join));
5664
}
5765

66+
/**
67+
* @group legacy
68+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getAlias()" directly instead.
69+
*/
5870
public function testGetJoinAliasWithJoin()
5971
{
6072
$join = new Join('INNER_JOIN', 'relatedDummy', 'a_1', null, 'a_1.name = r.name');
6173
$this->assertEquals('a_1', QueryJoinParser::getJoinAlias($join));
6274
}
6375

76+
/**
77+
* @group legacy
78+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getJoinAlias()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\Join::getAlias()" directly instead.
79+
*/
6480
public function testGetJoinAliasWithClassJoin()
6581
{
6682
$join = new Join('LEFT_JOIN', RelatedDummy::class, 'a_1', null, 'a_1.name = r.name');
6783
$this->assertEquals('a_1', QueryJoinParser::getJoinAlias($join));
6884
}
6985

86+
/**
87+
* @group legacy
88+
* @expectedDeprecation The use of "ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryJoinParser::getOrderByParts()" is deprecated since 2.3 and will be removed in 3.0. Use "Doctrine\ORM\Query\Expr\OrderBy::getParts()" directly instead.
89+
*/
7090
public function testGetOrderByPartsWithOrderBy()
7191
{
7292
$orderBy = new OrderBy('name', 'asc');

0 commit comments

Comments
 (0)