1
1
<?php
2
2
3
+ declare (strict_types=1 );
4
+
3
5
namespace Doctrine \ODM \MongoDB \Aggregation ;
4
6
5
7
use Doctrine \ODM \MongoDB \DocumentManager ;
6
8
use Doctrine \ODM \MongoDB \Iterator \CachingIterator ;
7
9
use Doctrine \ODM \MongoDB \Iterator \HydratingIterator ;
8
10
use Doctrine \ODM \MongoDB \Iterator \Iterator ;
11
+ use Doctrine \ODM \MongoDB \Mapping \ClassMetadata ;
12
+ use Doctrine \ODM \MongoDB \Persisters \DocumentPersister ;
9
13
use Doctrine \ODM \MongoDB \Query \Expr as QueryExpr ;
10
14
use GeoJson \Geometry \Point ;
11
15
use MongoDB \Collection ;
12
16
use MongoDB \Driver \Cursor ;
17
+ use function array_map ;
18
+ use function array_merge ;
19
+ use function array_unshift ;
20
+ use function is_array ;
13
21
14
22
/**
15
23
* Fluent interface for building aggregation pipelines.
@@ -26,7 +34,7 @@ class Builder
26
34
/**
27
35
* The ClassMetadata instance.
28
36
*
29
- * @var \Doctrine\ODM\MongoDB\Mapping\ ClassMetadata
37
+ * @var ClassMetadata
30
38
*/
31
39
private $ class ;
32
40
@@ -50,7 +58,6 @@ class Builder
50
58
/**
51
59
* Create a new aggregation builder.
52
60
*
53
- * @param DocumentManager $dm
54
61
* @param string $documentName
55
62
*/
56
63
public function __construct (DocumentManager $ dm , $ documentName )
@@ -127,8 +134,6 @@ public function bucketAuto()
127
134
* the pipeline returns an error.
128
135
*
129
136
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/collStats/
130
- * @since 1.5
131
- *
132
137
* @return Stage\CollStats
133
138
*/
134
139
public function collStats ()
@@ -200,7 +205,7 @@ public function facet()
200
205
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/geoNear/
201
206
*
202
207
* @param float|array|Point $x
203
- * @param float $y
208
+ * @param float $y
204
209
* @return Stage\GeoNear
205
210
*/
206
211
public function geoNear ($ x , $ y = null )
@@ -221,7 +226,9 @@ public function geoNear($x, $y = null)
221
226
public function getPipeline ()
222
227
{
223
228
$ pipeline = array_map (
224
- function (Stage $ stage ) { return $ stage ->getExpression (); },
229
+ function (Stage $ stage ) {
230
+ return $ stage ->getExpression ();
231
+ },
225
232
$ this ->stages
226
233
);
227
234
@@ -240,12 +247,12 @@ function (Stage $stage) { return $stage->getExpression(); },
240
247
/**
241
248
* Returns a certain stage from the pipeline
242
249
*
243
- * @param integer $index
250
+ * @param int $index
244
251
* @return Stage
245
252
*/
246
253
public function getStage ($ index )
247
254
{
248
- if ( ! isset ($ this ->stages [$ index ])) {
255
+ if (! isset ($ this ->stages [$ index ])) {
249
256
throw new \OutOfRangeException ("Could not find stage with index {$ index }. " );
250
257
}
251
258
@@ -311,7 +318,7 @@ public function indexStats()
311
318
*
312
319
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/limit/
313
320
*
314
- * @param integer $limit
321
+ * @param int $limit
315
322
* @return Stage\Limit
316
323
*/
317
324
public function limit ($ limit )
@@ -424,7 +431,7 @@ public function replaceRoot($expression = null)
424
431
*
425
432
* @see https://docs.mongodb.org/manual/reference/operator/aggregation/sample/
426
433
*
427
- * @param integer $size
434
+ * @param int $size
428
435
* @return Stage\Sample
429
436
*/
430
437
public function sample ($ size )
@@ -438,7 +445,7 @@ public function sample($size)
438
445
*
439
446
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/skip/
440
447
*
441
- * @param integer $skip
448
+ * @param int $skip
442
449
* @return Stage\Skip
443
450
*/
444
451
public function skip ($ skip )
@@ -456,7 +463,7 @@ public function skip($skip)
456
463
* @see http://docs.mongodb.org/manual/reference/operator/aggregation/sort/
457
464
*
458
465
* @param array|string $fieldName Field name or array of field/order pairs
459
- * @param integer |string $order Field order (if one field is specified)
466
+ * @param int |string $order Field order (if one field is specified)
460
467
* @return Stage\Sort
461
468
*/
462
469
public function sort ($ fieldName , $ order = null )
@@ -497,7 +504,6 @@ public function unwind($fieldName)
497
504
}
498
505
499
506
/**
500
- * @param Stage $stage
501
507
* @return Stage
502
508
*/
503
509
protected function addStage (Stage $ stage )
@@ -524,18 +530,13 @@ private function applyFilters(array $query)
524
530
}
525
531
526
532
/**
527
- * @return \Doctrine\ODM\MongoDB\Persisters\ DocumentPersister
533
+ * @return DocumentPersister
528
534
*/
529
535
private function getDocumentPersister ()
530
536
{
531
537
return $ this ->dm ->getUnitOfWork ()->getDocumentPersister ($ this ->class ->name );
532
538
}
533
539
534
- /**
535
- * @param Cursor $cursor
536
- *
537
- * @return Iterator
538
- */
539
540
private function prepareIterator (Cursor $ cursor ): Iterator
540
541
{
541
542
$ class = null ;
0 commit comments