Skip to content

Commit ccaa1a4

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 8e4ea1b commit ccaa1a4

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
@@ -170,7 +170,7 @@ public function count(string $fieldName): Stage\Count
170170
/**
171171
* Create a new Expr instance that can be used as an expression with the Builder
172172
*/
173-
public function createExpr(): Expr
173+
public function createAggregationExpression(): Expr
174174
{
175175
return new Expr($this->dm, $this->class);
176176
}
@@ -198,7 +198,15 @@ public function execute(array $options = []): Iterator
198198
*/
199199
public function expr(): Expr
200200
{
201-
return $this->createExpr();
201+
trigger_deprecation(
202+
'doctrine/mongodb-odm',
203+
'2.3',
204+
'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.',
205+
__METHOD__,
206+
static::class
207+
);
208+
209+
return $this->createAggregationExpression();
202210
}
203211

204212
/**

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

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

333333
/**
334334
* Returns a new expression object
335+
*
336+
* @return static
335337
*/
336-
public function createExpr(): self
338+
public function createAggregationExpression(): self
337339
{
338340
return new static($this->dm, $this->class);
339341
}
@@ -472,20 +474,15 @@ public function exp($exponent): self
472474
*/
473475
public function expr(): self
474476
{
475-
return $this->createExpr();
476-
}
477+
trigger_deprecation(
478+
'doctrine/mongodb-odm',
479+
'2.3',
480+
'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.',
481+
__METHOD__,
482+
static::class
483+
);
477484

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

491488
/**

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;
@@ -116,7 +117,7 @@ public function all(array $values): self
116117
* Create a new Expr instance that can be used to build partial expressions
117118
* for other operator methods.
118119
*/
119-
public function createExpr(): Expr
120+
public function createQueryExpression(): Expr
120121
{
121122
return $this->builder->matchExpr();
122123
}
@@ -177,20 +178,28 @@ public function exists(bool $bool): self
177178
*/
178179
public function expr(): Expr
179180
{
180-
return $this->createExpr();
181+
trigger_deprecation(
182+
'doctrine/mongodb-odm',
183+
'2.3',
184+
'The "%s" method is deprecated. Please use "%s::createQueryExpression" instead.',
185+
__METHOD__,
186+
static::class
187+
);
188+
189+
return $this->createQueryExpression();
181190
}
182191

183192
/**
184193
* Specify $expr criteria for the current field.
185194
*
186-
* @see Expr::exprOp()
195+
* @param array|Aggregation\Expr $expression
187196
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
188197
*
189-
* @param array|\Doctrine\ODM\MongoDB\Aggregation\Expr $expression
198+
* @see Expr::aggregationExpression()
190199
*/
191-
public function exprOp($expression): self
200+
public function aggregationExpression($expression): self
192201
{
193-
$this->query->exprOp($expression);
202+
$this->query->aggregationExpression($expression);
194203

195204
return $this;
196205
}

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(): array
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)