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
);

0 commit comments

Comments
 (0)