Skip to content

Commit 06a95f1

Browse files
author
Vincent Le Henaff
committed
+ update methods name refactoring as suggested in PR #2343 (exprOr to aggregationExpression and createExpr to createQueryExpression and createAggregationExpression)
+ add depreciation triggers + refactoring associated tests - remove unnecessary exprOp in Aggregation\Expr
1 parent 61aafa3 commit 06a95f1

File tree

6 files changed

+57
-33
lines changed

6 files changed

+57
-33
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function count(string $fieldName): Stage\Count
165165
/**
166166
* Create a new Expr instance that can be used as an expression with the Builder
167167
*/
168-
public function createExpr(): Expr
168+
public function createAggregationExpression(): Expr
169169
{
170170
return new Expr($this->dm, $this->class);
171171
}
@@ -193,7 +193,15 @@ public function execute(array $options = []): Iterator
193193
*/
194194
public function expr(): Expr
195195
{
196-
return $this->createExpr();
196+
trigger_deprecation(
197+
'doctrine/mongodb-odm',
198+
'2.3',
199+
'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.',
200+
__METHOD__,
201+
static::class
202+
);
203+
204+
return $this->createAggregationExpression();
197205
}
198206

199207
/**

lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,10 @@ public static function convertExpression($expression)
335335

336336
/**
337337
* Returns a new expression object
338+
*
339+
* @return static
338340
*/
339-
public function createExpr(): self
341+
public function createAggregationExpression(): self
340342
{
341343
return new static($this->dm, $this->class);
342344
}
@@ -475,20 +477,15 @@ public function exp($exponent): self
475477
*/
476478
public function expr(): self
477479
{
478-
return $this->createExpr();
479-
}
480+
trigger_deprecation(
481+
'doctrine/mongodb-odm',
482+
'2.3',
483+
'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.',
484+
__METHOD__,
485+
static::class
486+
);
480487

481-
/**
482-
* Specify $expr criteria for the current field.
483-
*
484-
* @see Builder::expr()
485-
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
486-
*
487-
* @param array|self $expression
488-
*/
489-
public function exprOp($expression): self
490-
{
491-
return $this->operator('$expr', $expression);
488+
return $this->createAggregationExpression();
492489
}
493490

494491
/**

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\ODM\MongoDB\Aggregation\Stage;
66

7+
use Doctrine\ODM\MongoDB\Aggregation;
78
use Doctrine\ODM\MongoDB\Aggregation\Builder;
89
use Doctrine\ODM\MongoDB\Aggregation\Stage;
910
use Doctrine\ODM\MongoDB\Query\Expr;
@@ -119,7 +120,7 @@ public function all(array $values): self
119120
* Create a new Expr instance that can be used to build partial expressions
120121
* for other operator methods.
121122
*/
122-
public function createExpr(): Expr
123+
public function createQueryExpression(): Expr
123124
{
124125
return $this->builder->matchExpr();
125126
}
@@ -180,20 +181,28 @@ public function exists(bool $bool): self
180181
*/
181182
public function expr(): Expr
182183
{
183-
return $this->createExpr();
184+
trigger_deprecation(
185+
'doctrine/mongodb-odm',
186+
'2.3',
187+
'The "%s" method is deprecated. Please use "%s::createQueryExpression" instead.',
188+
__METHOD__,
189+
static::class
190+
);
191+
192+
return $this->createQueryExpression();
184193
}
185194

186195
/**
187196
* Specify $expr criteria for the current field.
188197
*
189-
* @see Expr::exprOp()
198+
* @param array|Aggregation\Expr $expression
190199
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
191200
*
192-
* @param array|\Doctrine\ODM\MongoDB\Aggregation\Expr $expression
201+
* @see Expr::aggregationExpression()
193202
*/
194-
public function exprOp($expression): self
203+
public function aggregationExpression($expression): self
195204
{
196-
$this->query->exprOp($expression);
205+
$this->query->aggregationExpression($expression);
197206

198207
return $this;
199208
}

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ODM\MongoDB\Query;
66

77
use BadMethodCallException;
8+
use Doctrine\ODM\MongoDB\Aggregation;
89
use Doctrine\ODM\MongoDB\DocumentManager;
910
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
1011
use GeoJson\Geometry\Geometry;
@@ -369,7 +370,7 @@ public function count(): self
369370
/**
370371
* Create a new Expr instance that can be used as an expression with the Builder
371372
*/
372-
public function createExpr(): Expr
373+
public function createQueryExpression(): Expr
373374
{
374375
$expr = new Expr($this->dm);
375376
$expr->setClassMetadata($this->class);
@@ -509,20 +510,28 @@ public function exists(bool $bool): self
509510
*/
510511
public function expr(): Expr
511512
{
512-
return $this->createExpr();
513+
trigger_deprecation(
514+
'doctrine/mongodb-odm',
515+
'2.3',
516+
'The "%s" method is deprecated. Please use "%s::createQueryExpression" instead.',
517+
__METHOD__,
518+
static::class
519+
);
520+
521+
return $this->createQueryExpression();
513522
}
514523

515524
/**
516525
* Specify $expr criteria for the current field.
517526
*
518-
* @see Expr::exprOp()
527+
* @param array|Aggregation\Expr $expression
519528
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
520529
*
521-
* @param array|Expr $expression
530+
* @see Aggregation\Expr::aggregationExpression()
522531
*/
523-
public function exprOp($expression): self
532+
public function aggregationExpression($expression): self
524533
{
525-
$this->expr->exprOp($expression);
534+
$this->expr->aggregationExpression($expression);
526535

527536
return $this;
528537
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\ODM\MongoDB\Query;
66

77
use BadMethodCallException;
8+
use Doctrine\ODM\MongoDB\Aggregation;
89
use Doctrine\ODM\MongoDB\DocumentManager;
910
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
1011
use Doctrine\ODM\MongoDB\Mapping\MappingException;
@@ -407,12 +408,12 @@ public function elemMatch($expression): self
407408
/**
408409
* Specify $expr criteria for the current field.
409410
*
410-
* @see Builder::exprOp()
411+
* @see Builder::aggregationExpression()
411412
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
412413
*
413-
* @param array|Expr $expression
414+
* @param array|Aggregation\Expr $expression
414415
*/
415-
public function exprOp($expression): self
416+
public function aggregationExpression($expression): self
416417
{
417418
return $this->operator('$expr', $expression);
418419
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ public static function provideExpressionOperators()
194194
'operator' => 'exp',
195195
'args' => ['$field'],
196196
],
197-
'exprOp' => [
197+
'aggregationExpression' => [
198198
'expected' => ['$expr' => ['$eq' => ['$field', '$otherField']]],
199-
'operator' => 'exprOp',
199+
'operator' => 'aggregationExpression',
200200
'args' => [['$eq' => ['$field', '$otherField']]],
201201
],
202202
'filter' => [

0 commit comments

Comments
 (0)