Skip to content

Commit 773f8b9

Browse files
committed
Replace andX/orX with and/or
1 parent c2b8e6e commit 773f8b9

File tree

4 files changed

+43
-11
lines changed

4 files changed

+43
-11
lines changed

UPGRADE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# Upgrade to 2.11
2+
3+
## Deprecated `ExpressionBuilder` methods
4+
5+
The usage of the `andX()` and `orX()` methods of the `ExpressionBuilder` class has been deprecated. Use `and()` and `or()` instead.
6+
17
# Upgrade to 2.10
28

39
## Deprecated `Doctrine\DBAL\Event\ConnectionEventArgs` methods

lib/Doctrine/DBAL/Query/Expression/ExpressionBuilder.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(Connection $connection)
5252
*
5353
* @return CompositeExpression
5454
*/
55-
public function andX($x = null)
55+
public function and($x = null)
5656
{
5757
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
5858
}
@@ -71,11 +71,37 @@ public function andX($x = null)
7171
*
7272
* @return CompositeExpression
7373
*/
74-
public function orX($x = null)
74+
public function or($x = null)
7575
{
7676
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
7777
}
7878

79+
/**
80+
* @deprecated Use `and()` instead.
81+
*
82+
* @param mixed $x Optional clause. Defaults = null, but requires
83+
* at least one defined when converting to string.
84+
*
85+
* @return CompositeExpression
86+
*/
87+
public function andX($x = null)
88+
{
89+
return $this->and(...func_get_args());
90+
}
91+
92+
/**
93+
* @deprecated Use `and()` instead.
94+
*
95+
* @param mixed $x Optional clause. Defaults = null, but requires
96+
* at least one defined when converting to string.
97+
*
98+
* @return CompositeExpression
99+
*/
100+
public function orX($x = null)
101+
{
102+
return $this->or(...func_get_args());
103+
}
104+
79105
/**
80106
* Creates a comparison expression.
81107
*

tests/Doctrine/Tests/DBAL/Query/Expression/ExpressionBuilderTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ protected function setUp() : void
2929
/**
3030
* @param string[]|CompositeExpression[] $parts
3131
*
32-
* @dataProvider provideDataForAndX
32+
* @dataProvider provideDataForAnd
3333
*/
34-
public function testAndX(array $parts, string $expected) : void
34+
public function testAnd(array $parts, string $expected) : void
3535
{
36-
$composite = $this->expr->andX();
36+
$composite = $this->expr->and();
3737

3838
foreach ($parts as $part) {
3939
$composite->add($part);
@@ -45,7 +45,7 @@ public function testAndX(array $parts, string $expected) : void
4545
/**
4646
* @return mixed[][]
4747
*/
48-
public static function provideDataForAndX() : iterable
48+
public static function provideDataForAnd() : iterable
4949
{
5050
return [
5151
[
@@ -90,11 +90,11 @@ public static function provideDataForAndX() : iterable
9090
/**
9191
* @param string[]|CompositeExpression[] $parts
9292
*
93-
* @dataProvider provideDataForOrX
93+
* @dataProvider provideDataForOr
9494
*/
95-
public function testOrX(array $parts, string $expected) : void
95+
public function testOr(array $parts, string $expected) : void
9696
{
97-
$composite = $this->expr->orX();
97+
$composite = $this->expr->or();
9898

9999
foreach ($parts as $part) {
100100
$composite->add($part);
@@ -106,7 +106,7 @@ public function testOrX(array $parts, string $expected) : void
106106
/**
107107
* @return mixed[][]
108108
*/
109-
public static function provideDataForOrX() : iterable
109+
public static function provideDataForOr() : iterable
110110
{
111111
return [
112112
[

tests/Doctrine/Tests/DBAL/Query/QueryBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testSelectWithSimpleWhere() : void
6868

6969
$qb->select('u.id')
7070
->from('users', 'u')
71-
->where($expr->andX($expr->eq('u.nickname', '?')));
71+
->where($expr->and($expr->eq('u.nickname', '?')));
7272

7373
self::assertEquals('SELECT u.id FROM users u WHERE u.nickname = ?', (string) $qb);
7474
}

0 commit comments

Comments
 (0)