Skip to content

Commit b387bff

Browse files
Vincent Le Henaffvincent-le-henaff
authored andcommitted
+ 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 67e6913 commit b387bff

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
@@ -163,7 +163,7 @@ public function count(string $fieldName): Stage\Count
163163
/**
164164
* Create a new Expr instance that can be used as an expression with the Builder
165165
*/
166-
public function createExpr(): Expr
166+
public function createAggregationExpression(): Expr
167167
{
168168
return new Expr($this->dm, $this->class);
169169
}
@@ -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
@@ -326,8 +326,10 @@ public static function convertExpression($expression)
326326

327327
/**
328328
* Returns a new expression object
329+
*
330+
* @return static
329331
*/
330-
public function createExpr(): self
332+
public function createAggregationExpression(): self
331333
{
332334
return new static($this->dm, $this->class);
333335
}
@@ -466,20 +468,15 @@ public function exp($exponent): self
466468
*/
467469
public function expr(): self
468470
{
469-
return $this->createExpr();
470-
}
471+
trigger_deprecation(
472+
'doctrine/mongodb-odm',
473+
'2.3',
474+
'The "%s" method is deprecated. Please use "%s::createAggregationExpression" instead.',
475+
__METHOD__,
476+
static::class
477+
);
471478

472-
/**
473-
* Specify $expr criteria for the current field.
474-
*
475-
* @see Builder::expr()
476-
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
477-
*
478-
* @param array|self $expression
479-
*/
480-
public function exprOp($expression): self
481-
{
482-
return $this->operator('$expr', $expression);
479+
return $this->createAggregationExpression();
483480
}
484481

485482
/**

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;
@@ -118,7 +119,7 @@ public function all(array $values): self
118119
* Create a new Expr instance that can be used to build partial expressions
119120
* for other operator methods.
120121
*/
121-
public function createExpr(): Expr
122+
public function createQueryExpression(): Expr
122123
{
123124
return $this->builder->matchExpr();
124125
}
@@ -179,20 +180,28 @@ public function exists(bool $bool): self
179180
*/
180181
public function expr(): Expr
181182
{
182-
return $this->createExpr();
183+
trigger_deprecation(
184+
'doctrine/mongodb-odm',
185+
'2.3',
186+
'The "%s" method is deprecated. Please use "%s::createQueryExpression" instead.',
187+
__METHOD__,
188+
static::class
189+
);
190+
191+
return $this->createQueryExpression();
183192
}
184193

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

197206
return $this;
198207
}

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;
@@ -359,7 +360,7 @@ public function count(): self
359360
/**
360361
* Create a new Expr instance that can be used as an expression with the Builder
361362
*/
362-
public function createExpr(): Expr
363+
public function createQueryExpression(): Expr
363364
{
364365
$expr = new Expr($this->dm);
365366
$expr->setClassMetadata($this->class);
@@ -499,20 +500,28 @@ public function exists(bool $bool): self
499500
*/
500501
public function expr(): Expr
501502
{
502-
return $this->createExpr();
503+
trigger_deprecation(
504+
'doctrine/mongodb-odm',
505+
'2.3',
506+
'The "%s" method is deprecated. Please use "%s::createQueryExpression" instead.',
507+
__METHOD__,
508+
static::class
509+
);
510+
511+
return $this->createQueryExpression();
503512
}
504513

505514
/**
506515
* Specify $expr criteria for the current field.
507516
*
508-
* @see Expr::exprOp()
517+
* @param array|Aggregation\Expr $expression
509518
* @see https://docs.mongodb.com/manual/reference/operator/query/expr/
510519
*
511-
* @param array|Expr $expression
520+
* @see Aggregation\Expr::aggregationExpression()
512521
*/
513-
public function exprOp($expression): self
522+
public function aggregationExpression($expression): self
514523
{
515-
$this->expr->exprOp($expression);
524+
$this->expr->aggregationExpression($expression);
516525

517526
return $this;
518527
}

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
@@ -192,9 +192,9 @@ public static function provideExpressionOperators(): array
192192
'operator' => 'exp',
193193
'args' => ['$field'],
194194
],
195-
'exprOp' => [
195+
'aggregationExpression' => [
196196
'expected' => ['$expr' => ['$eq' => ['$field', '$otherField']]],
197-
'operator' => 'exprOp',
197+
'operator' => 'aggregationExpression',
198198
'args' => [['$eq' => ['$field', '$otherField']]],
199199
],
200200
'filter' => [

0 commit comments

Comments
 (0)