Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Builder often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Builder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class Builder |
||
18 | { |
||
19 | /** |
||
20 | * The DocumentManager instance for this query |
||
21 | * |
||
22 | * @var DocumentManager |
||
23 | */ |
||
24 | private $dm; |
||
25 | |||
26 | /** |
||
27 | * The ClassMetadata instance. |
||
28 | * |
||
29 | * @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadata |
||
30 | */ |
||
31 | private $class; |
||
32 | |||
33 | /** |
||
34 | * The current field we are operating on. |
||
35 | * |
||
36 | * @todo Change this to private once ODM requires doctrine/mongodb 1.1+ |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $currentField; |
||
40 | |||
41 | /** |
||
42 | * Whether or not to hydrate the data to documents. |
||
43 | * |
||
44 | * @var boolean |
||
45 | */ |
||
46 | private $hydrate = true; |
||
47 | |||
48 | /** |
||
49 | * Whether or not to refresh the data for documents that are already in the identity map. |
||
50 | * |
||
51 | * @var boolean |
||
52 | */ |
||
53 | private $refresh = false; |
||
54 | |||
55 | /** |
||
56 | * Array of primer Closure instances. |
||
57 | * |
||
58 | * @var array |
||
59 | */ |
||
60 | private $primers = array(); |
||
61 | |||
62 | /** |
||
63 | * Whether or not to register documents in UnitOfWork. |
||
64 | * |
||
65 | * @var bool |
||
66 | */ |
||
67 | private $readOnly; |
||
68 | |||
69 | /** |
||
70 | * The Collection instance. |
||
71 | * |
||
72 | * @var Collection |
||
73 | */ |
||
74 | private $collection; |
||
75 | |||
76 | /** |
||
77 | * Array containing the query data. |
||
78 | * |
||
79 | * @var array |
||
80 | */ |
||
81 | private $query = ['type' => Query::TYPE_FIND]; |
||
82 | |||
83 | /** |
||
84 | * The Expr instance used for building this query. |
||
85 | * |
||
86 | * This object includes the query criteria and the "new object" used for |
||
87 | * insert and update queries. |
||
88 | * |
||
89 | * @var Expr $expr |
||
90 | */ |
||
91 | private $expr; |
||
92 | |||
93 | /** |
||
94 | * Construct a Builder |
||
95 | * |
||
96 | * @param DocumentManager $dm |
||
97 | * @param string[]|string|null $documentName (optional) an array of document names, the document name, or none |
||
98 | */ |
||
99 | 285 | public function __construct(DocumentManager $dm, $documentName = null) |
|
107 | |||
108 | 1 | public function __clone() |
|
112 | |||
113 | /** |
||
114 | * Add one or more $and clauses to the current query. |
||
115 | * |
||
116 | * You can create a new expression using the {@link Builder::expr()} method. |
||
117 | * |
||
118 | * @see Expr::addAnd() |
||
119 | * @see http://docs.mongodb.org/manual/reference/operator/and/ |
||
120 | * @param array|Expr $expression |
||
121 | * @return $this |
||
122 | */ |
||
123 | 4 | public function addAnd($expression /* , $expression2, ... */) |
|
128 | |||
129 | /** |
||
130 | * Add one or more $nor clauses to the current query. |
||
131 | * |
||
132 | * You can create a new expression using the {@link Builder::expr()} method. |
||
133 | * |
||
134 | * @see Expr::addNor() |
||
135 | * @see http://docs.mongodb.org/manual/reference/operator/nor/ |
||
136 | * @param array|Expr $expression |
||
137 | * @return $this |
||
138 | */ |
||
139 | 3 | public function addNor($expression /* , $expression2, ... */) |
|
144 | |||
145 | /** |
||
146 | * Add one or more $or clauses to the current query. |
||
147 | * |
||
148 | * You can create a new expression using the {@link Builder::expr()} method. |
||
149 | * |
||
150 | * @see Expr::addOr() |
||
151 | * @see http://docs.mongodb.org/manual/reference/operator/or/ |
||
152 | * @param array|Expr $expression |
||
153 | * @return $this |
||
154 | */ |
||
155 | 6 | public function addOr($expression /* , $expression2, ... */) |
|
160 | |||
161 | /** |
||
162 | * Append one or more values to the current array field only if they do not |
||
163 | * already exist in the array. |
||
164 | * |
||
165 | * If the field does not exist, it will be set to an array containing the |
||
166 | * unique value(s) in the argument. If the field is not an array, the query |
||
167 | * will yield an error. |
||
168 | * |
||
169 | * Multiple values may be specified by provided an Expr object and using |
||
170 | * {@link Expr::each()}. |
||
171 | * |
||
172 | * @see Expr::addToSet() |
||
173 | * @see http://docs.mongodb.org/manual/reference/operator/addToSet/ |
||
174 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
175 | * @param mixed|Expr $valueOrExpression |
||
176 | * @return $this |
||
177 | */ |
||
178 | 5 | public function addToSet($valueOrExpression) |
|
183 | |||
184 | /** |
||
185 | * Specify $all criteria for the current field. |
||
186 | * |
||
187 | * @see Expr::all() |
||
188 | * @see http://docs.mongodb.org/manual/reference/operator/all/ |
||
189 | * @param array $values |
||
190 | * @return $this |
||
191 | */ |
||
192 | 3 | public function all(array $values) |
|
197 | |||
198 | /** |
||
199 | * Apply a bitwise and operation on the current field. |
||
200 | * |
||
201 | * @see Expr::bitAnd() |
||
202 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
203 | * @param int $value |
||
204 | * @return $this |
||
205 | */ |
||
206 | 1 | public function bitAnd($value) |
|
211 | |||
212 | /** |
||
213 | * Apply a bitwise or operation on the current field. |
||
214 | * |
||
215 | * @see Expr::bitOr() |
||
216 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
217 | * @param int $value |
||
218 | * @return $this |
||
219 | */ |
||
220 | 1 | public function bitOr($value) |
|
225 | |||
226 | /** |
||
227 | * Matches documents where all of the bit positions given by the query are |
||
228 | * clear. |
||
229 | * |
||
230 | * @see Expr::bitsAllClear() |
||
231 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/ |
||
232 | * @param int|array|\MongoBinData $value |
||
233 | * @return $this |
||
234 | */ |
||
235 | 1 | public function bitsAllClear($value) |
|
240 | |||
241 | /** |
||
242 | * Matches documents where all of the bit positions given by the query are |
||
243 | * set. |
||
244 | * |
||
245 | * @see Expr::bitsAllSet() |
||
246 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllSet/ |
||
247 | * @param int|array|\MongoBinData $value |
||
248 | * @return $this |
||
249 | */ |
||
250 | 1 | public function bitsAllSet($value) |
|
255 | |||
256 | /** |
||
257 | * Matches documents where any of the bit positions given by the query are |
||
258 | * clear. |
||
259 | * |
||
260 | * @see Expr::bitsAnyClear() |
||
261 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnyClear/ |
||
262 | * @param int|array|\MongoBinData $value |
||
263 | * @return $this |
||
264 | */ |
||
265 | 1 | public function bitsAnyClear($value) |
|
270 | |||
271 | /** |
||
272 | * Matches documents where any of the bit positions given by the query are |
||
273 | * set. |
||
274 | * |
||
275 | * @see Expr::bitsAnySet() |
||
276 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnySet/ |
||
277 | * @param int|array|\MongoBinData $value |
||
278 | * @return $this |
||
279 | */ |
||
280 | 1 | public function bitsAnySet($value) |
|
285 | |||
286 | /** |
||
287 | * Apply a bitwise xor operation on the current field. |
||
288 | * |
||
289 | * @see Expr::bitXor() |
||
290 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
291 | * @param int $value |
||
292 | * @return $this |
||
293 | */ |
||
294 | 1 | public function bitXor($value) |
|
299 | |||
300 | /** |
||
301 | * A boolean flag to enable or disable case sensitive search for $text |
||
302 | * criteria. |
||
303 | * |
||
304 | * This method must be called after text(). |
||
305 | * |
||
306 | * @see Expr::caseSensitive() |
||
307 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
308 | * @param bool $caseSensitive |
||
309 | * @return $this |
||
310 | * @throws \BadMethodCallException if the query does not already have $text criteria |
||
311 | * |
||
312 | * @since 1.3 |
||
313 | */ |
||
314 | 1 | public function caseSensitive($caseSensitive) |
|
319 | |||
320 | /** |
||
321 | * Associates a comment to any expression taking a query predicate. |
||
322 | * |
||
323 | * @see Expr::comment() |
||
324 | * @see http://docs.mongodb.org/manual/reference/operator/query/comment/ |
||
325 | * @param string $comment |
||
326 | * @return $this |
||
327 | */ |
||
328 | 1 | public function comment($comment) |
|
333 | |||
334 | /** |
||
335 | * Change the query type to count. |
||
336 | * |
||
337 | * @return $this |
||
338 | */ |
||
339 | public function count() |
||
344 | |||
345 | /** |
||
346 | * Sets the value of the current field to the current date, either as a date or a timestamp. |
||
347 | * |
||
348 | * @see Expr::currentDate() |
||
349 | * @see http://docs.mongodb.org/manual/reference/operator/currentDate/ |
||
350 | * @param string $type |
||
351 | * @return $this |
||
352 | */ |
||
353 | 3 | public function currentDate($type = 'date') |
|
358 | |||
359 | /** |
||
360 | * Return an array of information about the Builder state for debugging. |
||
361 | * |
||
362 | * The $name parameter may be used to return a specific key from the |
||
363 | * internal $query array property. If omitted, the entire array will be |
||
364 | * returned. |
||
365 | * |
||
366 | * @param string $name |
||
367 | * @return mixed |
||
368 | */ |
||
369 | 28 | public function debug($name = null) |
|
373 | |||
374 | /** |
||
375 | * A boolean flag to enable or disable diacritic sensitive search for $text |
||
376 | * criteria. |
||
377 | * |
||
378 | * This method must be called after text(). |
||
379 | * |
||
380 | * @see Builder::diacriticSensitive() |
||
381 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
382 | * @param bool $diacriticSensitive |
||
383 | * @return $this |
||
384 | * @throws \BadMethodCallException if the query does not already have $text criteria |
||
385 | * |
||
386 | * @since 1.3 |
||
387 | */ |
||
388 | 1 | public function diacriticSensitive($diacriticSensitive) |
|
393 | |||
394 | /** |
||
395 | * Change the query type to a distinct command. |
||
396 | * |
||
397 | * @see http://docs.mongodb.org/manual/reference/command/distinct/ |
||
398 | * @param string $field |
||
399 | * @return $this |
||
400 | */ |
||
401 | 2 | public function distinct($field) |
|
407 | |||
408 | /** |
||
409 | * Set whether the query should return its result as an EagerCursor. |
||
410 | * |
||
411 | * @param boolean $bool |
||
412 | * @return $this |
||
413 | */ |
||
414 | 5 | public function eagerCursor($bool = true) |
|
423 | |||
424 | /** |
||
425 | * Specify $elemMatch criteria for the current field. |
||
426 | * |
||
427 | * You can create a new expression using the {@link Builder::expr()} method. |
||
428 | * |
||
429 | * @see Expr::elemMatch() |
||
430 | * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/ |
||
431 | * @param array|Expr $expression |
||
432 | * @return $this |
||
433 | */ |
||
434 | 6 | public function elemMatch($expression) |
|
439 | |||
440 | /** |
||
441 | * Specify an equality match for the current field. |
||
442 | * |
||
443 | * @see Expr::equals() |
||
444 | * @param mixed $value |
||
445 | * @return $this |
||
446 | */ |
||
447 | 75 | public function equals($value) |
|
452 | |||
453 | /** |
||
454 | * Set one or more fields to be excluded from the query projection. |
||
455 | * |
||
456 | * If fields have been selected for inclusion, only the "_id" field may be |
||
457 | * excluded. |
||
458 | * |
||
459 | * @param array|string $fieldName,... |
||
460 | * @return $this |
||
461 | */ |
||
462 | 6 | View Code Duplication | public function exclude($fieldName = null) |
476 | |||
477 | /** |
||
478 | * Specify $exists criteria for the current field. |
||
479 | * |
||
480 | * @see Expr::exists() |
||
481 | * @see http://docs.mongodb.org/manual/reference/operator/exists/ |
||
482 | * @param boolean $bool |
||
483 | * @return $this |
||
484 | */ |
||
485 | 5 | public function exists($bool) |
|
490 | |||
491 | /** |
||
492 | * Create a new Expr instance that can be used as an expression with the Builder |
||
493 | * |
||
494 | * @return Expr $expr |
||
495 | */ |
||
496 | 26 | public function expr() |
|
503 | |||
504 | /** |
||
505 | * Set the current field to operate on. |
||
506 | * |
||
507 | * @param string $field |
||
508 | * @return $this |
||
509 | */ |
||
510 | 144 | public function field($field) |
|
517 | |||
518 | /** |
||
519 | * Set the "finalize" option for a mapReduce or group command. |
||
520 | * |
||
521 | * @param string|\MongoCode $finalize |
||
522 | * @return $this |
||
523 | * @throws \BadMethodCallException if the query is not a mapReduce or group command |
||
524 | */ |
||
525 | 2 | View Code Duplication | public function finalize($finalize) |
542 | |||
543 | /** |
||
544 | * Change the query type to find and optionally set and change the class being queried. |
||
545 | * |
||
546 | * @param string $documentName |
||
547 | * @return $this |
||
548 | */ |
||
549 | 12 | public function find($documentName = null) |
|
556 | |||
557 | /** |
||
558 | * @param string $documentName |
||
559 | * @return $this |
||
560 | */ |
||
561 | 1 | public function findAndRemove($documentName = null) |
|
568 | |||
569 | /** |
||
570 | * @param string $documentName |
||
571 | * @return $this |
||
572 | */ |
||
573 | 13 | public function findAndUpdate($documentName = null) |
|
580 | |||
581 | /** |
||
582 | * Add $geoIntersects criteria with a GeoJSON geometry to the query. |
||
583 | * |
||
584 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
585 | * geometry's JSON representation. |
||
586 | * |
||
587 | * @see Expr::geoIntersects() |
||
588 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
589 | * @param array|Geometry $geometry |
||
590 | * @return $this |
||
591 | */ |
||
592 | 1 | public function geoIntersects($geometry) |
|
597 | |||
598 | /** |
||
599 | * Add $geoWithin criteria with a GeoJSON geometry to the query. |
||
600 | * |
||
601 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
602 | * geometry's JSON representation. |
||
603 | * |
||
604 | * @see Expr::geoWithin() |
||
605 | * @see http://docs.mongodb.org/manual/reference/operator/geoWithin/ |
||
606 | * @param array|Geometry $geometry |
||
607 | * @return $this |
||
608 | */ |
||
609 | 1 | public function geoWithin($geometry) |
|
614 | |||
615 | /** |
||
616 | * Add $geoWithin criteria with a $box shape to the query. |
||
617 | * |
||
618 | * A rectangular polygon will be constructed from a pair of coordinates |
||
619 | * corresponding to the bottom left and top right corners. |
||
620 | * |
||
621 | * Note: the $box operator only supports legacy coordinate pairs and 2d |
||
622 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
623 | * |
||
624 | * @see Expr::geoWithinBox() |
||
625 | * @see http://docs.mongodb.org/manual/reference/operator/box/ |
||
626 | * @param float $x1 |
||
627 | * @param float $y1 |
||
628 | * @param float $x2 |
||
629 | * @param float $y2 |
||
630 | * @return $this |
||
631 | */ |
||
632 | 1 | public function geoWithinBox($x1, $y1, $x2, $y2) |
|
637 | |||
638 | /** |
||
639 | * Add $geoWithin criteria with a $center shape to the query. |
||
640 | * |
||
641 | * Note: the $center operator only supports legacy coordinate pairs and 2d |
||
642 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
643 | * |
||
644 | * @see Expr::geoWithinCenter() |
||
645 | * @see http://docs.mongodb.org/manual/reference/operator/center/ |
||
646 | * @param float $x |
||
647 | * @param float $y |
||
648 | * @param float $radius |
||
649 | * @return $this |
||
650 | */ |
||
651 | 1 | public function geoWithinCenter($x, $y, $radius) |
|
656 | |||
657 | /** |
||
658 | * Add $geoWithin criteria with a $centerSphere shape to the query. |
||
659 | * |
||
660 | * Note: the $centerSphere operator supports both 2d and 2dsphere indexes. |
||
661 | * |
||
662 | * @see Expr::geoWithinCenterSphere() |
||
663 | * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/ |
||
664 | * @param float $x |
||
665 | * @param float $y |
||
666 | * @param float $radius |
||
667 | * @return $this |
||
668 | */ |
||
669 | 1 | public function geoWithinCenterSphere($x, $y, $radius) |
|
674 | |||
675 | /** |
||
676 | * Add $geoWithin criteria with a $polygon shape to the query. |
||
677 | * |
||
678 | * Point coordinates are in x, y order (easting, northing for projected |
||
679 | * coordinates, longitude, latitude for geographic coordinates). |
||
680 | * |
||
681 | * The last point coordinate is implicitly connected with the first. |
||
682 | * |
||
683 | * Note: the $polygon operator only supports legacy coordinate pairs and 2d |
||
684 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
685 | * |
||
686 | * @see Expr::geoWithinPolygon() |
||
687 | * @see http://docs.mongodb.org/manual/reference/operator/polygon/ |
||
688 | * @param array $point,... Three or more point coordinate tuples |
||
689 | * @return $this |
||
690 | */ |
||
691 | 1 | public function geoWithinPolygon(/* array($x1, $y1), ... */) |
|
696 | |||
697 | /** |
||
698 | * Return the expression's "new object". |
||
699 | * |
||
700 | * @see Expr::getNewObj() |
||
701 | * @return array |
||
702 | */ |
||
703 | 13 | public function getNewObj() |
|
707 | |||
708 | /** |
||
709 | * Gets the Query executable. |
||
710 | * |
||
711 | * @param array $options |
||
712 | * @return Query $query |
||
713 | */ |
||
714 | 150 | public function getQuery(array $options = array()) |
|
775 | |||
776 | /** |
||
777 | * Return the expression's query criteria. |
||
778 | * |
||
779 | * @see Expr::getQuery() |
||
780 | * @return array |
||
781 | */ |
||
782 | 33 | public function getQueryArray() |
|
786 | |||
787 | /** |
||
788 | * Get the type of this query. |
||
789 | * |
||
790 | * @return integer $type |
||
791 | */ |
||
792 | 2 | public function getType() |
|
796 | |||
797 | /** |
||
798 | * Specify $gt criteria for the current field. |
||
799 | * |
||
800 | * @see Expr::gt() |
||
801 | * @see http://docs.mongodb.org/manual/reference/operator/gt/ |
||
802 | * @param mixed $value |
||
803 | * @return $this |
||
804 | */ |
||
805 | 2 | public function gt($value) |
|
810 | |||
811 | /** |
||
812 | * Specify $gte criteria for the current field. |
||
813 | * |
||
814 | * @see Expr::gte() |
||
815 | * @see http://docs.mongodb.org/manual/reference/operator/gte/ |
||
816 | * @param mixed $value |
||
817 | * @return $this |
||
818 | */ |
||
819 | 2 | public function gte($value) |
|
824 | |||
825 | /** |
||
826 | * Set the index hint for the query. |
||
827 | * |
||
828 | * @param array|string $index |
||
829 | * @return $this |
||
830 | */ |
||
831 | public function hint($index) |
||
836 | |||
837 | /** |
||
838 | * @param bool $bool |
||
839 | * @return $this |
||
840 | */ |
||
841 | 17 | public function hydrate($bool = true) |
|
846 | |||
847 | /** |
||
848 | * Set the immortal cursor flag. |
||
849 | * |
||
850 | * @param boolean $bool |
||
851 | * @return $this |
||
852 | */ |
||
853 | public function immortal($bool = true) |
||
858 | |||
859 | /** |
||
860 | * Specify $in criteria for the current field. |
||
861 | * |
||
862 | * @see Expr::in() |
||
863 | * @see http://docs.mongodb.org/manual/reference/operator/in/ |
||
864 | * @param array $values |
||
865 | * @return $this |
||
866 | */ |
||
867 | 24 | public function in(array $values) |
|
872 | |||
873 | /** |
||
874 | * Increment the current field. |
||
875 | * |
||
876 | * If the field does not exist, it will be set to this value. |
||
877 | * |
||
878 | * @see Expr::inc() |
||
879 | * @see http://docs.mongodb.org/manual/reference/operator/inc/ |
||
880 | * @param float|integer $value |
||
881 | * @return $this |
||
882 | */ |
||
883 | 6 | public function inc($value) |
|
888 | |||
889 | /** |
||
890 | * @param object $document |
||
891 | * @return $this |
||
892 | */ |
||
893 | 6 | public function includesReferenceTo($document) |
|
898 | |||
899 | /** |
||
900 | * @param string $documentName |
||
901 | * @return $this |
||
902 | */ |
||
903 | 1 | public function insert($documentName = null) |
|
910 | |||
911 | /** |
||
912 | * Set the $language option for $text criteria. |
||
913 | * |
||
914 | * This method must be called after text(). |
||
915 | * |
||
916 | * @see Expr::language() |
||
917 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
918 | * @param string $language |
||
919 | * @return $this |
||
920 | */ |
||
921 | 1 | public function language($language) |
|
926 | |||
927 | /** |
||
928 | * Set the limit for the query. |
||
929 | * |
||
930 | * This is only relevant for find queries and geoNear and mapReduce |
||
931 | * commands. |
||
932 | * |
||
933 | * @see Query::prepareCursor() |
||
934 | * @param integer $limit |
||
935 | * @return $this |
||
936 | */ |
||
937 | 2 | public function limit($limit) |
|
942 | |||
943 | /** |
||
944 | * Specify $lt criteria for the current field. |
||
945 | * |
||
946 | * @see Expr::lte() |
||
947 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
948 | * @param mixed $value |
||
949 | * @return $this |
||
950 | */ |
||
951 | public function lt($value) |
||
956 | |||
957 | /** |
||
958 | * Specify $lte criteria for the current field. |
||
959 | * |
||
960 | * @see Expr::lte() |
||
961 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
962 | * @param mixed $value |
||
963 | * @return $this |
||
964 | */ |
||
965 | public function lte($value) |
||
970 | |||
971 | /** |
||
972 | * Change the query type to a mapReduce command. |
||
973 | * |
||
974 | * The "reduce" option is not specified when calling this method; it must |
||
975 | * be set with the {@link Builder::reduce()} method. |
||
976 | * |
||
977 | * The "out" option defaults to inline, like {@link Builder::mapReduce()}. |
||
978 | * |
||
979 | * @see http://docs.mongodb.org/manual/reference/command/mapReduce/ |
||
980 | * @param string|\MongoCode $map |
||
981 | * @return $this |
||
982 | */ |
||
983 | 1 | public function map($map) |
|
994 | |||
995 | /** |
||
996 | * Change the query type to a mapReduce command. |
||
997 | * |
||
998 | * @see http://docs.mongodb.org/manual/reference/command/mapReduce/ |
||
999 | * @param string|\MongoCode $map |
||
1000 | * @param string|\MongoCode $reduce |
||
1001 | * @param array|string $out |
||
1002 | * @param array $options |
||
1003 | * @return $this |
||
1004 | */ |
||
1005 | 1 | public function mapReduce($map, $reduce, $out = ['inline' => true], array $options = []) |
|
1016 | |||
1017 | /** |
||
1018 | * Set additional options for a mapReduce command. |
||
1019 | * |
||
1020 | * @param array $options |
||
1021 | * @return $this |
||
1022 | * @throws \BadMethodCallException if the query is not a mapReduce command |
||
1023 | */ |
||
1024 | 1 | View Code Duplication | public function mapReduceOptions(array $options) |
1033 | |||
1034 | /** |
||
1035 | * Updates the value of the field to a specified value if the specified value is greater than the current value of the field. |
||
1036 | * |
||
1037 | * @see Expr::max() |
||
1038 | * @see http://docs.mongodb.org/manual/reference/operator/update/max/ |
||
1039 | * @param mixed $value |
||
1040 | * @return $this |
||
1041 | */ |
||
1042 | 1 | public function max($value) |
|
1047 | |||
1048 | /** |
||
1049 | * Specifies a cumulative time limit in milliseconds for processing operations on a cursor. |
||
1050 | * |
||
1051 | * @param int $ms |
||
1052 | * @return $this |
||
1053 | */ |
||
1054 | public function maxTimeMS($ms) |
||
1059 | |||
1060 | /** |
||
1061 | * Updates the value of the field to a specified value if the specified value is less than the current value of the field. |
||
1062 | * |
||
1063 | * @see Expr::min() |
||
1064 | * @see http://docs.mongodb.org/manual/reference/operator/update/min/ |
||
1065 | * @param mixed $value |
||
1066 | * @return $this |
||
1067 | */ |
||
1068 | 1 | public function min($value) |
|
1073 | |||
1074 | /** |
||
1075 | * Specify $mod criteria for the current field. |
||
1076 | * |
||
1077 | * @see Expr::mod() |
||
1078 | * @see http://docs.mongodb.org/manual/reference/operator/mod/ |
||
1079 | * @param float|integer $divisor |
||
1080 | * @param float|integer $remainder |
||
1081 | * @return $this |
||
1082 | */ |
||
1083 | 1 | public function mod($divisor, $remainder = 0) |
|
1088 | |||
1089 | /** |
||
1090 | * Multiply the current field. |
||
1091 | * |
||
1092 | * If the field does not exist, it will be set to 0. |
||
1093 | * |
||
1094 | * @see Expr::mul() |
||
1095 | * @see http://docs.mongodb.org/manual/reference/operator/mul/ |
||
1096 | * @param float|integer $value |
||
1097 | * @return $this |
||
1098 | */ |
||
1099 | 1 | public function mul($value) |
|
1104 | |||
1105 | /** |
||
1106 | * Add $near criteria to the query. |
||
1107 | * |
||
1108 | * A GeoJSON point may be provided as the first and only argument for |
||
1109 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
1110 | * an array corresponding to the point's JSON representation. |
||
1111 | * |
||
1112 | * @see Expr::near() |
||
1113 | * @see http://docs.mongodb.org/manual/reference/operator/near/ |
||
1114 | * @param float|array|Point $x |
||
1115 | * @param float $y |
||
1116 | * @return $this |
||
1117 | */ |
||
1118 | 1 | public function near($x, $y = null) |
|
1123 | |||
1124 | /** |
||
1125 | * Add $nearSphere criteria to the query. |
||
1126 | * |
||
1127 | * A GeoJSON point may be provided as the first and only argument for |
||
1128 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
1129 | * an array corresponding to the point's JSON representation. |
||
1130 | * |
||
1131 | * @see Expr::nearSphere() |
||
1132 | * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/ |
||
1133 | * @param float|array|Point $x |
||
1134 | * @param float $y |
||
1135 | * @return $this |
||
1136 | */ |
||
1137 | 1 | public function nearSphere($x, $y = null) |
|
1142 | |||
1143 | /** |
||
1144 | * Negates an expression for the current field. |
||
1145 | * |
||
1146 | * You can create a new expression using the {@link Builder::expr()} method. |
||
1147 | * |
||
1148 | * @see Expr::not() |
||
1149 | * @see http://docs.mongodb.org/manual/reference/operator/not/ |
||
1150 | * @param array|Expr $expression |
||
1151 | * @return $this |
||
1152 | */ |
||
1153 | 3 | public function not($expression) |
|
1158 | |||
1159 | /** |
||
1160 | * Specify $ne criteria for the current field. |
||
1161 | * |
||
1162 | * @see Expr::notEqual() |
||
1163 | * @see http://docs.mongodb.org/manual/reference/operator/ne/ |
||
1164 | * @param mixed $value |
||
1165 | * @return $this |
||
1166 | */ |
||
1167 | 4 | public function notEqual($value) |
|
1172 | |||
1173 | /** |
||
1174 | * Specify $nin criteria for the current field. |
||
1175 | * |
||
1176 | * @see Expr::notIn() |
||
1177 | * @see http://docs.mongodb.org/manual/reference/operator/nin/ |
||
1178 | * @param array $values |
||
1179 | * @return $this |
||
1180 | */ |
||
1181 | 4 | public function notIn(array $values) |
|
1186 | |||
1187 | /** |
||
1188 | * Set the "out" option for a mapReduce command. |
||
1189 | * |
||
1190 | * @param array|string $out |
||
1191 | * @return $this |
||
1192 | * @throws \BadMethodCallException if the query is not a mapReduce command |
||
1193 | */ |
||
1194 | 1 | View Code Duplication | public function out($out) |
1203 | |||
1204 | /** |
||
1205 | * Remove the first element from the current array field. |
||
1206 | * |
||
1207 | * @see Expr::popFirst() |
||
1208 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
1209 | * @return $this |
||
1210 | */ |
||
1211 | 2 | public function popFirst() |
|
1216 | |||
1217 | /** |
||
1218 | * Remove the last element from the current array field. |
||
1219 | * |
||
1220 | * @see Expr::popLast() |
||
1221 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
1222 | * @return $this |
||
1223 | */ |
||
1224 | 1 | public function popLast() |
|
1229 | |||
1230 | /** |
||
1231 | * Use a primer to eagerly load all references in the current field. |
||
1232 | * |
||
1233 | * If $primer is true or a callable is provided, referenced documents for |
||
1234 | * this field will loaded into UnitOfWork immediately after the query is |
||
1235 | * executed. This will avoid multiple queries due to lazy initialization of |
||
1236 | * Proxy objects. |
||
1237 | * |
||
1238 | * If $primer is false, no priming will take place. That is also the default |
||
1239 | * behavior. |
||
1240 | * |
||
1241 | * If a custom callable is used, its signature should conform to the default |
||
1242 | * Closure defined in {@link ReferencePrimer::__construct()}. |
||
1243 | * |
||
1244 | * @param boolean|callable $primer |
||
1245 | * @return $this |
||
1246 | * @throws \InvalidArgumentException If $primer is not boolean or callable |
||
1247 | */ |
||
1248 | 25 | public function prime($primer = true) |
|
1267 | |||
1268 | /** |
||
1269 | * Remove all elements matching the given value or expression from the |
||
1270 | * current array field. |
||
1271 | * |
||
1272 | * @see Expr::pull() |
||
1273 | * @see http://docs.mongodb.org/manual/reference/operator/pull/ |
||
1274 | * @param mixed|Expr $valueOrExpression |
||
1275 | * @return $this |
||
1276 | */ |
||
1277 | 1 | public function pull($valueOrExpression) |
|
1282 | |||
1283 | /** |
||
1284 | * Remove all elements matching any of the given values from the current |
||
1285 | * array field. |
||
1286 | * |
||
1287 | * @see Expr::pullAll() |
||
1288 | * @see http://docs.mongodb.org/manual/reference/operator/pullAll/ |
||
1289 | * @param array $values |
||
1290 | * @return $this |
||
1291 | */ |
||
1292 | 1 | public function pullAll(array $values) |
|
1297 | |||
1298 | /** |
||
1299 | * Append one or more values to the current array field. |
||
1300 | * |
||
1301 | * If the field does not exist, it will be set to an array containing the |
||
1302 | * value(s) in the argument. If the field is not an array, the query |
||
1303 | * will yield an error. |
||
1304 | * |
||
1305 | * Multiple values may be specified by providing an Expr object and using |
||
1306 | * {@link Expr::each()}. {@link Expr::slice()} and {@link Expr::sort()} may |
||
1307 | * also be used to limit and order array elements, respectively. |
||
1308 | * |
||
1309 | * @see Expr::push() |
||
1310 | * @see http://docs.mongodb.org/manual/reference/operator/push/ |
||
1311 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
1312 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
1313 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
1314 | * @param mixed|Expr $valueOrExpression |
||
1315 | * @return $this |
||
1316 | */ |
||
1317 | 6 | public function push($valueOrExpression) |
|
1322 | |||
1323 | /** |
||
1324 | * Specify $gte and $lt criteria for the current field. |
||
1325 | * |
||
1326 | * This method is shorthand for specifying $gte criteria on the lower bound |
||
1327 | * and $lt criteria on the upper bound. The upper bound is not inclusive. |
||
1328 | * |
||
1329 | * @see Expr::range() |
||
1330 | * @param mixed $start |
||
1331 | * @param mixed $end |
||
1332 | * @return $this |
||
1333 | */ |
||
1334 | 3 | public function range($start, $end) |
|
1339 | |||
1340 | /** |
||
1341 | * @param bool $bool |
||
1342 | * @return $this |
||
1343 | */ |
||
1344 | 2 | public function readOnly($bool = true) |
|
1349 | |||
1350 | /** |
||
1351 | * Set the "reduce" option for a mapReduce or group command. |
||
1352 | * |
||
1353 | * @param string|\MongoCode $reduce |
||
1354 | * @return $this |
||
1355 | * @throws \BadMethodCallException if the query is not a mapReduce or group command |
||
1356 | */ |
||
1357 | 2 | View Code Duplication | public function reduce($reduce) |
1374 | |||
1375 | /** |
||
1376 | * @param object $document |
||
1377 | * @return $this |
||
1378 | */ |
||
1379 | 10 | public function references($document) |
|
1384 | |||
1385 | /** |
||
1386 | * @param bool $bool |
||
1387 | * @return $this |
||
1388 | */ |
||
1389 | 5 | public function refresh($bool = true) |
|
1394 | |||
1395 | /** |
||
1396 | * @param string $documentName |
||
1397 | * @return $this |
||
1398 | */ |
||
1399 | 1 | public function remove($documentName = null) |
|
1406 | |||
1407 | /** |
||
1408 | * Rename the current field. |
||
1409 | * |
||
1410 | * @see Expr::rename() |
||
1411 | * @see http://docs.mongodb.org/manual/reference/operator/rename/ |
||
1412 | * @param string $name |
||
1413 | * @return $this |
||
1414 | */ |
||
1415 | public function rename($name) |
||
1420 | |||
1421 | /** |
||
1422 | * @param bool $bool |
||
1423 | * @return $this |
||
1424 | */ |
||
1425 | 4 | public function returnNew($bool = true) |
|
1432 | |||
1433 | /** |
||
1434 | * Set one or more fields to be included in the query projection. |
||
1435 | * |
||
1436 | * @param array|string $fieldName,... |
||
1437 | * @return $this |
||
1438 | */ |
||
1439 | 19 | View Code Duplication | public function select($fieldName = null) |
1453 | |||
1454 | /** |
||
1455 | * Select only matching embedded documents in an array field for the query |
||
1456 | * projection. |
||
1457 | * |
||
1458 | * @see http://docs.mongodb.org/manual/reference/projection/elemMatch/ |
||
1459 | * @param string $fieldName |
||
1460 | * @param array|Expr $expression |
||
1461 | * @return $this |
||
1462 | */ |
||
1463 | 2 | public function selectElemMatch($fieldName, $expression) |
|
1471 | |||
1472 | /** |
||
1473 | * Select a metadata field for the query projection. |
||
1474 | * |
||
1475 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/ |
||
1476 | * @param string $fieldName |
||
1477 | * @param string $metaDataKeyword |
||
1478 | * @return $this |
||
1479 | */ |
||
1480 | 2 | public function selectMeta($fieldName, $metaDataKeyword) |
|
1485 | |||
1486 | /** |
||
1487 | * Select a slice of an array field for the query projection. |
||
1488 | * |
||
1489 | * The $countOrSkip parameter has two very different meanings, depending on |
||
1490 | * whether or not $limit is provided. See the MongoDB documentation for more |
||
1491 | * information. |
||
1492 | * |
||
1493 | * @see http://docs.mongodb.org/manual/reference/projection/slice/ |
||
1494 | * @param string $fieldName |
||
1495 | * @param integer $countOrSkip Count parameter, or skip if limit is specified |
||
1496 | * @param integer $limit Limit parameter used in conjunction with skip |
||
1497 | * @return $this |
||
1498 | */ |
||
1499 | 3 | public function selectSlice($fieldName, $countOrSkip, $limit = null) |
|
1508 | |||
1509 | /** |
||
1510 | * Set the current field to a value. |
||
1511 | * |
||
1512 | * This is only relevant for insert, update, or findAndUpdate queries. For |
||
1513 | * update and findAndUpdate queries, the $atomic parameter will determine |
||
1514 | * whether or not a $set operator is used. |
||
1515 | * |
||
1516 | * @see Expr::set() |
||
1517 | * @see http://docs.mongodb.org/manual/reference/operator/set/ |
||
1518 | * @param mixed $value |
||
1519 | * @param boolean $atomic |
||
1520 | * @return $this |
||
1521 | */ |
||
1522 | 16 | public function set($value, $atomic = true) |
|
1527 | |||
1528 | /** |
||
1529 | * Set the expression's "new object". |
||
1530 | * |
||
1531 | * @see Expr::setNewObj() |
||
1532 | * @param array $newObj |
||
1533 | * @return $this |
||
1534 | */ |
||
1535 | public function setNewObj(array $newObj) |
||
1540 | |||
1541 | /** |
||
1542 | * Set the current field to the value if the document is inserted in an |
||
1543 | * upsert operation. |
||
1544 | * |
||
1545 | * If an update operation with upsert: true results in an insert of a |
||
1546 | * document, then $setOnInsert assigns the specified values to the fields in |
||
1547 | * the document. If the update operation does not result in an insert, |
||
1548 | * $setOnInsert does nothing. |
||
1549 | * |
||
1550 | * @see Expr::setOnInsert() |
||
1551 | * @see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ |
||
1552 | * @param mixed $value |
||
1553 | * @return $this |
||
1554 | */ |
||
1555 | 2 | public function setOnInsert($value) |
|
1560 | |||
1561 | /** |
||
1562 | * Set the read preference for the query. |
||
1563 | * |
||
1564 | * This is only relevant for read-only queries and commands. |
||
1565 | * |
||
1566 | * @see http://docs.mongodb.org/manual/core/read-preference/ |
||
1567 | * @param ReadPreference $readPreference |
||
1568 | * @return $this |
||
1569 | */ |
||
1570 | 6 | public function setReadPreference(ReadPreference $readPreference) |
|
1575 | |||
1576 | /** |
||
1577 | * Set the expression's query criteria. |
||
1578 | * |
||
1579 | * @see Expr::setQuery() |
||
1580 | * @param array $query |
||
1581 | * @return $this |
||
1582 | */ |
||
1583 | 18 | public function setQueryArray(array $query) |
|
1588 | |||
1589 | /** |
||
1590 | * Specify $size criteria for the current field. |
||
1591 | * |
||
1592 | * @see Expr::size() |
||
1593 | * @see http://docs.mongodb.org/manual/reference/operator/size/ |
||
1594 | * @param integer $size |
||
1595 | * @return $this |
||
1596 | */ |
||
1597 | 1 | public function size($size) |
|
1602 | |||
1603 | /** |
||
1604 | * Set the skip for the query cursor. |
||
1605 | * |
||
1606 | * This is only relevant for find queries, or mapReduce queries that store |
||
1607 | * results in an output collecton and return a cursor. |
||
1608 | * |
||
1609 | * @see Query::prepareCursor() |
||
1610 | * @param integer $skip |
||
1611 | * @return $this |
||
1612 | */ |
||
1613 | public function skip($skip) |
||
1618 | |||
1619 | /** |
||
1620 | * Set the snapshot cursor flag. |
||
1621 | * |
||
1622 | * @param boolean $bool |
||
1623 | * @return $this |
||
1624 | */ |
||
1625 | public function snapshot($bool = true) |
||
1630 | |||
1631 | /** |
||
1632 | * Set one or more field/order pairs on which to sort the query. |
||
1633 | * |
||
1634 | * If sorting by multiple fields, the first argument should be an array of |
||
1635 | * field name (key) and order (value) pairs. |
||
1636 | * |
||
1637 | * @param array|string $fieldName Field name or array of field/order pairs |
||
1638 | * @param int|string $order Field order (if one field is specified) |
||
1639 | * @return $this |
||
1640 | */ |
||
1641 | 31 | public function sort($fieldName, $order = 1) |
|
1658 | |||
1659 | /** |
||
1660 | * Specify a projected metadata field on which to sort the query. |
||
1661 | * |
||
1662 | * Sort order is not configurable for metadata fields. Sorting by a metadata |
||
1663 | * field requires the same field and $meta expression to exist in the |
||
1664 | * projection document. This method will call {@link Builder::selectMeta()} |
||
1665 | * if the field is not already set in the projection. |
||
1666 | * |
||
1667 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/#sort |
||
1668 | * @param string $fieldName Field name of the projected metadata |
||
1669 | * @param string $metaDataKeyword |
||
1670 | * @return $this |
||
1671 | */ |
||
1672 | 2 | public function sortMeta($fieldName, $metaDataKeyword) |
|
1686 | |||
1687 | /** |
||
1688 | * Specify $text criteria for the current field. |
||
1689 | * |
||
1690 | * The $language option may be set with {@link Builder::language()}. |
||
1691 | * |
||
1692 | * @see Expr::text() |
||
1693 | * @see http://docs.mongodb.org/master/reference/operator/query/text/ |
||
1694 | * @param string $search |
||
1695 | * @return $this |
||
1696 | */ |
||
1697 | 1 | public function text($search) |
|
1702 | |||
1703 | /** |
||
1704 | * Specify $type criteria for the current field. |
||
1705 | * |
||
1706 | * @see Expr::type() |
||
1707 | * @see http://docs.mongodb.org/manual/reference/operator/type/ |
||
1708 | * @param integer $type |
||
1709 | * @return $this |
||
1710 | */ |
||
1711 | 2 | public function type($type) |
|
1716 | |||
1717 | /** |
||
1718 | * Unset the current field. |
||
1719 | * |
||
1720 | * The field will be removed from the document (not set to null). |
||
1721 | * |
||
1722 | * @see Expr::unsetField() |
||
1723 | * @see http://docs.mongodb.org/manual/reference/operator/unset/ |
||
1724 | * @return $this |
||
1725 | */ |
||
1726 | 4 | public function unsetField() |
|
1731 | |||
1732 | /** |
||
1733 | * @param string $documentName |
||
1734 | * @return $this |
||
1735 | */ |
||
1736 | 21 | View Code Duplication | public function updateOne($documentName = null) |
1744 | |||
1745 | /** |
||
1746 | * @param string $documentName |
||
1747 | * @return $this |
||
1748 | */ |
||
1749 | 3 | View Code Duplication | public function updateMany($documentName = null) |
1757 | |||
1758 | /** |
||
1759 | * Set the "upsert" option for an update or findAndUpdate query. |
||
1760 | * |
||
1761 | * @param boolean $bool |
||
1762 | * @return $this |
||
1763 | */ |
||
1764 | 7 | public function upsert($bool = true) |
|
1769 | |||
1770 | /** |
||
1771 | * Specify a JavaScript expression to use for matching documents. |
||
1772 | * |
||
1773 | * @see Expr::where() |
||
1774 | * @see http://docs.mongodb.org/manual/reference/operator/where/ |
||
1775 | * @param string|\MongoCode $javascript |
||
1776 | * @return $this |
||
1777 | */ |
||
1778 | 3 | public function where($javascript) |
|
1783 | |||
1784 | /** |
||
1785 | * Get Discriminator Values |
||
1786 | * |
||
1787 | * @param \Traversable $classNames |
||
1788 | * @return array an array of discriminatorValues (mixed type) |
||
1789 | * @throws \InvalidArgumentException if the number of found collections > 1 |
||
1790 | */ |
||
1791 | 2 | private function getDiscriminatorValues($classNames) |
|
1806 | |||
1807 | /** |
||
1808 | * @param string[]|string $documentName an array of document names or just one. |
||
1809 | */ |
||
1810 | 284 | private function setDocumentName($documentName) |
|
1836 | } |
||
1837 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.