Skip to content

Commit eb60a6f

Browse files
+ replaced Query\Builder::expr() calls to Query\Builder::createQueryExpression()
+ replaced Aggregation\Builder::expr() calls to Aggregation\Builder::createAggregationExpression() + minor psalm docblock update
1 parent 771b43d commit eb60a6f

File tree

17 files changed

+54
-46
lines changed

17 files changed

+54
-46
lines changed

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket/AbstractOutput.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(Builder $builder, Stage\AbstractBucket $bucket)
2525
parent::__construct($builder);
2626

2727
$this->bucket = $bucket;
28-
$this->expr = $builder->expr();
28+
$this->expr = $builder->createAggregationExpression();
2929
}
3030

3131
public function getExpression(): array

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Group.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct(Builder $builder)
1919
{
2020
parent::__construct($builder);
2121

22-
$this->expr = $builder->expr();
22+
$this->expr = $builder->createAggregationExpression();
2323
}
2424

2525
public function getExpression(): array

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/MatchStage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(Builder $builder)
2525
{
2626
parent::__construct($builder);
2727

28-
$this->query = $this->expr();
28+
$this->query = $this->createQueryExpression();
2929
}
3030

3131
/**

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Operator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(Builder $builder)
2727
{
2828
parent::__construct($builder);
2929

30-
$this->expr = $builder->expr();
30+
$this->expr = $builder->createAggregationExpression();
3131
}
3232

3333
/**

lib/Doctrine/ODM/MongoDB/Query/Builder.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function __clone()
122122
/**
123123
* Add one or more $and clauses to the current query.
124124
*
125-
* You can create a new expression using the {@link Builder::expr()} method.
125+
* You can create a new expression using the {@link Builder::createAggregationExpression()} method.
126126
*
127127
* @see Expr::addAnd()
128128
* @see https://docs.mongodb.com/manual/reference/operator/and/
@@ -140,7 +140,7 @@ public function addAnd($expression, ...$expressions): self
140140
/**
141141
* Add one or more $nor clauses to the current query.
142142
*
143-
* You can create a new expression using the {@link Builder::expr()} method.
143+
* You can create a new expression using the {@link Builder::createAggregationExpression()} method.
144144
*
145145
* @see Expr::addNor()
146146
* @see https://docs.mongodb.com/manual/reference/operator/nor/
@@ -158,7 +158,7 @@ public function addNor($expression, ...$expressions): self
158158
/**
159159
* Add one or more $or clauses to the current query.
160160
*
161-
* You can create a new expression using the {@link Builder::expr()} method.
161+
* You can create a new expression using the {@link Builder::createAggregationExpression()} method.
162162
*
163163
* @see Expr::addOr()
164164
* @see https://docs.mongodb.com/manual/reference/operator/or/
@@ -430,7 +430,7 @@ public function distinct(string $field): self
430430
/**
431431
* Specify $elemMatch criteria for the current field.
432432
*
433-
* You can create a new expression using the {@link Builder::expr()} method.
433+
* You can create a new expression using the {@link Builder::createAggregationExpression()} method.
434434
*
435435
* @see Expr::elemMatch()
436436
* @see https://docs.mongodb.com/manual/reference/operator/elemMatch/
@@ -465,6 +465,9 @@ public function equals($value): self
465465
* excluded.
466466
*
467467
* @param string[]|string $fieldName,...
468+
* @param null|string|string[] $fieldName
469+
*
470+
* @psalm-param 'comments'|array{0: 'name', 1: 'issues'}|null $fieldName
468471
*/
469472
public function exclude($fieldName = null): self
470473
{
@@ -1054,7 +1057,7 @@ public function nearSphere($x, $y = null): self
10541057
/**
10551058
* Negates an expression for the current field.
10561059
*
1057-
* You can create a new expression using the {@link Builder::expr()} method.
1060+
* You can create a new expression using the {@link Builder::createAggregationExpression()} method.
10581061
*
10591062
* @see Expr::not()
10601063
* @see https://docs.mongodb.com/manual/reference/operator/not/
@@ -1288,7 +1291,9 @@ public function returnNew(bool $bool = true): self
12881291
/**
12891292
* Set one or more fields to be included in the query projection.
12901293
*
1291-
* @param string[]|string $fieldName,...
1294+
* @param null|string|string[] $fieldName
1295+
*
1296+
* @return Builder
12921297
*/
12931298
public function select($fieldName = null): self
12941299
{

lib/Doctrine/ODM/MongoDB/Query/QueryExpressionVisitor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ public function walkComparison(Comparison $comparison): Expr
7171
case Comparison::NIN:
7272
$method = self::$operatorMethods[$comparison->getOperator()];
7373

74-
return $this->builder->expr()
74+
return $this->builder->createQueryExpression()
7575
->field($comparison->getField())
7676
->{$method}($this->walkValue($comparison->getValue()));
7777

7878
case Comparison::CONTAINS:
7979
$value = $this->walkValue($comparison->getValue());
8080

81-
return $this->builder->expr()
81+
return $this->builder->createQueryExpression()
8282
->field($comparison->getField())
8383
->equals(new Regex($value, ''));
8484

@@ -99,7 +99,7 @@ public function walkCompositeExpression(CompositeExpression $expr): Expr
9999
}
100100

101101
$method = self::$compositeMethods[$expr->getType()];
102-
$outputExpr = $this->builder->expr();
102+
$outputExpr = $this->builder->createQueryExpression();
103103

104104
foreach ($expr->getExpressionList() as $child) {
105105
$outputExpr->{$method}($this->dispatch($child));

lib/Doctrine/ODM/MongoDB/Types/DateImmutableType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class DateImmutableType extends DateType
1616
{
1717
/**
1818
* @return DateTimeImmutable
19+
*
20+
* @param \MongoDB\BSON\UTCDateTime|float $value
1921
*/
2022
public static function getDateTime($value): DateTimeInterface
2123
{

tests/Doctrine/ODM/MongoDB/Tests/Aggregation/BuilderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function testGetPipeline(): void
135135
->unwind('b')
136136
->redact()
137137
->cond(
138-
$builder->expr()->lte('$accessLevel', 3),
138+
$builder->createAggregationExpression()->lte('$accessLevel', 3),
139139
'$$KEEP',
140140
'$$REDACT'
141141
)
@@ -144,9 +144,9 @@ public function testGetPipeline(): void
144144
->includeFields(['user', 'amount', 'invoiceAddress'])
145145
->field('deliveryAddress')
146146
->cond(
147-
$builder->expr()
148-
->addAnd($builder->expr()->eq('$useAlternateDeliveryAddress', true))
149-
->addAnd($builder->expr()->ne('$deliveryAddress', null)),
147+
$builder->createAggregationExpression()
148+
->addAnd($builder->createAggregationExpression()->eq('$useAlternateDeliveryAddress', true))
149+
->addAnd($builder->createAggregationExpression()->ne('$deliveryAddress', null)),
150150
'$deliveryAddress',
151151
'$invoiceAddress'
152152
)
@@ -157,7 +157,7 @@ public function testGetPipeline(): void
157157
->sum(1)
158158
->field('amount')
159159
->expression(
160-
$builder->expr()
160+
$builder->createAggregationExpression()
161161
->field('total')
162162
->sum('$amount')
163163
->field('avg')
@@ -267,9 +267,9 @@ public function testPipelineConvertsTypes(): void
267267
->group()
268268
->field('id')
269269
->expression(
270-
$builder->expr()
270+
$builder->createAggregationExpression()
271271
->cond(
272-
$builder->expr()->lt('$createdAt', $dateTime),
272+
$builder->createAggregationExpression()->lt('$createdAt', $dateTime),
273273
true,
274274
false
275275
)

tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/RedactTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testRedactStage(): void
1919
$redactStage = new Redact($builder);
2020
$redactStage
2121
->cond(
22-
$builder->expr()->lte('$accessLevel', 3),
22+
$builder->createAggregationExpression()->lte('$accessLevel', 3),
2323
'$$KEEP',
2424
'$$REDACT'
2525
);
@@ -33,7 +33,7 @@ public function testRedactFromBuilder(): void
3333
$builder
3434
->redact()
3535
->cond(
36-
$builder->expr()->lte('$accessLevel', 3),
36+
$builder->createAggregationExpression()->lte('$accessLevel', 3),
3737
'$$KEEP',
3838
'$$REDACT'
3939
);

tests/Doctrine/ODM/MongoDB/Tests/Aggregation/Stage/ReplaceRootTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testTypeConversionWithDirectExpression(): void
4343
$mongoDate = new UTCDateTime((int) $dateTime->format('Uv'));
4444
$stage = $builder
4545
->replaceRoot(
46-
$builder->expr()
46+
$builder->createAggregationExpression()
4747
->field('isToday')
4848
->eq('$createdAt', $dateTime)
4949
);

tests/Doctrine/ODM/MongoDB/Tests/Functional/QueryTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function testAddElemMatch(): void
5353
$qb = $this->dm->createQueryBuilder(User::class);
5454
$embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class);
5555

56-
$qb->field('phonenumbers')->elemMatch($embeddedQb->expr()->field('phonenumber')->equals('6155139185'));
56+
$qb->field('phonenumbers')->elemMatch($embeddedQb->createQueryExpression()->field('phonenumber')->equals('6155139185'));
5757
$query = $qb->getQuery();
5858
$user = $query->getSingleResult();
5959
self::assertNotNull($user);
@@ -76,7 +76,8 @@ public function testAddElemMatchWithDeepFields(): void
7676
$qb = $this->dm->createQueryBuilder(User::class);
7777
$embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class);
7878

79-
$qb->field('phonenumbers')->elemMatch($embeddedQb->expr()->field('lastCalledBy.$id')->equals(new ObjectId($user1->getId())));
79+
$qb->field('phonenumbers')->elemMatch($embeddedQb->createQueryExpression()->field('lastCalledBy.$id')->equals(new ObjectId
80+
($user1->getId())));
8081
$query = $qb->getQuery();
8182
$user = $query->getSingleResult();
8283
self::assertNotNull($user);
@@ -91,12 +92,12 @@ public function testAddNot(): void
9192
$this->dm->flush();
9293

9394
$qb = $this->dm->createQueryBuilder(User::class);
94-
$qb->field('username')->not($qb->expr()->in(['boo']));
95+
$qb->field('username')->not($qb->createQueryExpression()->in(['boo']));
9596
$query = $qb->getQuery();
9697
$user = $query->getSingleResult();
9798
self::assertNull($user);
9899

99-
$qb->field('username')->not($qb->expr()->in(['1boo']));
100+
$qb->field('username')->not($qb->createQueryExpression()->in(['1boo']));
100101
$query = $qb->getQuery();
101102
$user = $query->getSingleResult();
102103
self::assertNotNull($user);

tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1674Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function testElemMatchUsesCorrectMapping(): void
1818
$builder
1919
->field('embedded')
2020
->elemMatch(
21-
$builder->expr()
21+
$builder->createQueryExpression()
2222
->field('id')
2323
->equals(1)
2424
);

tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH2251Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public function testElemMatchQuery(string $fieldName): void
2323
new ObjectId('5fae9a775ef4492e3c72b3f4'),
2424
];
2525

26-
$notIn = $builder->expr()->notIn($objectIds);
27-
$elemMatch = $builder->expr()
26+
$notIn = $builder->createQueryExpression()->notIn($objectIds);
27+
$elemMatch = $builder->createQueryExpression()
2828
->field($fieldName)
2929
->elemMatch($notIn);
3030

tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH596Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public function testExpressionPreparationDoesNotInjectFilterCriteria(): void
2626

2727
$repository = $this->dm->getRepository($class);
2828
$qb = $repository->createQueryBuilder();
29-
$qb->addOr($qb->expr()->field('name')->equals('foo'));
30-
$qb->addOr($qb->expr()->field('name')->equals('bar'));
29+
$qb->addOr($qb->createQueryExpression()->field('name')->equals('foo'));
30+
$qb->addOr($qb->createQueryExpression()->field('name')->equals('bar'));
3131

3232
$query = $qb->getQuery();
3333
$query = $query->getQuery();

tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ public function provideArrayUpdateOperatorsOnReferenceOne(): Generator
242242
public function testThatOrAcceptsAnotherQuery(): void
243243
{
244244
$qb = $this->getTestQueryBuilder();
245-
$qb->addOr($qb->expr()->field('firstName')->equals('Kris'));
246-
$qb->addOr($qb->expr()->field('firstName')->equals('Chris'));
245+
$qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Kris'));
246+
$qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Chris'));
247247

248248
self::assertEquals([
249249
'$or' => [
@@ -256,8 +256,8 @@ public function testThatOrAcceptsAnotherQuery(): void
256256
public function testThatAndAcceptsAnotherQuery(): void
257257
{
258258
$qb = $this->getTestQueryBuilder();
259-
$qb->addAnd($qb->expr()->field('hits')->gte(1));
260-
$qb->addAnd($qb->expr()->field('hits')->lt(5));
259+
$qb->addAnd($qb->createQueryExpression()->field('hits')->gte(1));
260+
$qb->addAnd($qb->createQueryExpression()->field('hits')->lt(5));
261261

262262
self::assertEquals([
263263
'$and' => [
@@ -270,8 +270,8 @@ public function testThatAndAcceptsAnotherQuery(): void
270270
public function testThatNorAcceptsAnotherQuery(): void
271271
{
272272
$qb = $this->getTestQueryBuilder();
273-
$qb->addNor($qb->expr()->field('firstName')->equals('Kris'));
274-
$qb->addNor($qb->expr()->field('firstName')->equals('Chris'));
273+
$qb->addNor($qb->createQueryExpression()->field('firstName')->equals('Kris'));
274+
$qb->addNor($qb->createQueryExpression()->field('firstName')->equals('Chris'));
275275

276276
self::assertEquals([
277277
'$nor' => [
@@ -284,7 +284,7 @@ public function testThatNorAcceptsAnotherQuery(): void
284284
public function testAddElemMatch(): void
285285
{
286286
$qb = $this->getTestQueryBuilder();
287-
$qb->field('phonenumbers')->elemMatch($qb->expr()->field('phonenumber')->equals('6155139185'));
287+
$qb->field('phonenumbers')->elemMatch($qb->createQueryExpression()->field('phonenumber')->equals('6155139185'));
288288
$expected = [
289289
'phonenumbers' => [
290290
'$elemMatch' => ['phonenumber' => '6155139185'],
@@ -296,7 +296,7 @@ public function testAddElemMatch(): void
296296
public function testAddNot(): void
297297
{
298298
$qb = $this->getTestQueryBuilder();
299-
$qb->field('username')->not($qb->expr()->in(['boo']));
299+
$qb->field('username')->not($qb->createQueryExpression()->in(['boo']));
300300
$expected = [
301301
'username' => [
302302
'$not' => [
@@ -662,7 +662,7 @@ public function testSelectElemMatchWithArray(): void
662662
public function testSelectElemMatchWithExpr(): void
663663
{
664664
$qb = $this->getTestQueryBuilder();
665-
$qb->selectElemMatch('addresses', $qb->expr()->field('state')->equals('ny'));
665+
$qb->selectElemMatch('addresses', $qb->createQueryExpression()->field('state')->equals('ny'));
666666

667667
$expected = ['addresses' => ['$elemMatch' => ['state' => 'ny']]];
668668

tests/Doctrine/ODM/MongoDB/Tests/Query/ExprTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testAndIsPrepared(): void
8787

8888
$qb = $this->dm->createQueryBuilder(User::class);
8989
$qb
90-
->addAnd($qb->expr()->field('groups.id')->in($ids))
90+
->addAnd($qb->createQueryExpression()->field('groups.id')->in($ids))
9191
->select('id')->hydrate(false);
9292
$query = $qb->getQuery();
9393
$debug = $query->debug('query');
@@ -102,7 +102,7 @@ public function testOrIsPrepared(): void
102102

103103
$qb = $this->dm->createQueryBuilder(User::class);
104104
$qb
105-
->addOr($qb->expr()->field('groups.id')->in($ids))
105+
->addOr($qb->createQueryExpression()->field('groups.id')->in($ids))
106106
->select('id')->hydrate(false);
107107
$query = $qb->getQuery();
108108
$debug = $query->debug('query');

tests/Doctrine/ODM/MongoDB/Tests/QueryTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public function testThatOrAcceptsAnotherQuery(): void
5959
$expression2 = ['firstName' => 'Chris'];
6060

6161
$qb = $this->dm->createQueryBuilder($class);
62-
$qb->addOr($qb->expr()->field('firstName')->equals('Kris'));
63-
$qb->addOr($qb->expr()->field('firstName')->equals('Chris'));
62+
$qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Kris'));
63+
$qb->addOr($qb->createQueryExpression()->field('firstName')->equals('Chris'));
6464

6565
self::assertEquals([
6666
'$or' => [
@@ -283,7 +283,7 @@ public function testElemMatch(): void
283283
$qb = $this->dm->createQueryBuilder(User::class);
284284
$embeddedQb = $this->dm->createQueryBuilder(Phonenumber::class);
285285

286-
$qb->field('phonenumbers')->elemMatch($embeddedQb->expr()
286+
$qb->field('phonenumbers')->elemMatch($embeddedQb->createQueryExpression()
287287
->field('lastCalledBy.id')->equals($refId));
288288
$query = $qb->getQuery();
289289

0 commit comments

Comments
 (0)