Skip to content

Commit 84328cd

Browse files
committed
Replace andX/orX with and/or
1 parent c2b8e6e commit 84328cd

File tree

5 files changed

+39
-25
lines changed

5 files changed

+39
-25
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

docs/en/reference/query-builder.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ Most notably you can use expressions to build nested And-/Or statements:
332332
->select('id', 'name')
333333
->from('users')
334334
->where(
335-
$queryBuilder->expr()->andX(
335+
$queryBuilder->expr()->and(
336336
$queryBuilder->expr()->eq('username', '?'),
337337
$queryBuilder->expr()->eq('email', '?')
338338
)
339339
);
340340
341-
The ``andX()`` and ``orX()`` methods accept an arbitrary amount
341+
The ``and()`` and ``or()`` methods accept an arbitrary amount
342342
of arguments and can be nested in each other.
343343

344344
There is a bunch of methods to create comparisons and other SQL snippets

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

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,27 @@ public function __construct(Connection $connection)
3939
}
4040

4141
/**
42-
* Creates a conjunction of the given boolean expressions.
42+
* Creates a conjunction of the given expressions.
4343
*
44-
* Example:
44+
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
45+
*/
46+
public function and(...$expressions) : CompositeExpression
47+
{
48+
return new CompositeExpression(CompositeExpression::TYPE_AND, $expressions);
49+
}
50+
51+
/**
52+
* Creates a disjunction of the given expressions.
4553
*
46-
* [php]
47-
* // (u.type = ?) AND (u.role = ?)
48-
* $expr->andX('u.type = ?', 'u.role = ?'));
54+
* @param string|CompositeExpression ...$expressions Requires at least one defined when converting to string.
55+
*/
56+
public function or(...$expressions) : CompositeExpression
57+
{
58+
return new CompositeExpression(CompositeExpression::TYPE_OR, $expressions);
59+
}
60+
61+
/**
62+
* @deprecated Use `and()` instead.
4963
*
5064
* @param mixed $x Optional clause. Defaults = null, but requires
5165
* at least one defined when converting to string.
@@ -54,17 +68,11 @@ public function __construct(Connection $connection)
5468
*/
5569
public function andX($x = null)
5670
{
57-
return new CompositeExpression(CompositeExpression::TYPE_AND, func_get_args());
71+
return $this->and(...func_get_args());
5872
}
5973

6074
/**
61-
* Creates a disjunction of the given boolean expressions.
62-
*
63-
* Example:
64-
*
65-
* [php]
66-
* // (u.type = ?) OR (u.role = ?)
67-
* $qb->where($qb->expr()->orX('u.type = ?', 'u.role = ?'));
75+
* @deprecated Use `or()` instead.
6876
*
6977
* @param mixed $x Optional clause. Defaults = null, but requires
7078
* at least one defined when converting to string.
@@ -73,7 +81,7 @@ public function andX($x = null)
7381
*/
7482
public function orX($x = null)
7583
{
76-
return new CompositeExpression(CompositeExpression::TYPE_OR, func_get_args());
84+
return $this->or(...func_get_args());
7785
}
7886

7987
/**

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)