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 |
||
31 | class Builder |
||
32 | { |
||
33 | /** |
||
34 | * The DocumentManager instance for this query |
||
35 | * |
||
36 | * @var DocumentManager |
||
37 | */ |
||
38 | private $dm; |
||
39 | |||
40 | /** |
||
41 | * The ClassMetadata instance. |
||
42 | * |
||
43 | * @var ClassMetadata |
||
44 | */ |
||
45 | private $class; |
||
46 | |||
47 | /** |
||
48 | * The current field we are operating on. |
||
49 | * |
||
50 | * @todo Change this to private once ODM requires doctrine/mongodb 1.1+ |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $currentField; |
||
54 | |||
55 | /** |
||
56 | * Whether or not to hydrate the data to documents. |
||
57 | * |
||
58 | * @var bool |
||
59 | */ |
||
60 | private $hydrate = true; |
||
61 | |||
62 | /** |
||
63 | * Whether or not to refresh the data for documents that are already in the identity map. |
||
64 | * |
||
65 | * @var bool |
||
66 | */ |
||
67 | private $refresh = false; |
||
68 | |||
69 | /** |
||
70 | * Array of primer Closure instances. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | private $primers = []; |
||
75 | |||
76 | /** |
||
77 | * Whether or not to register documents in UnitOfWork. |
||
78 | * |
||
79 | * @var bool |
||
80 | */ |
||
81 | private $readOnly = false; |
||
82 | |||
83 | /** @var bool */ |
||
84 | private $rewindable = true; |
||
85 | |||
86 | /** |
||
87 | * The Collection instance. |
||
88 | * |
||
89 | * @var Collection |
||
90 | */ |
||
91 | private $collection; |
||
92 | |||
93 | /** |
||
94 | * Array containing the query data. |
||
95 | * |
||
96 | * @var array |
||
97 | */ |
||
98 | private $query = ['type' => Query::TYPE_FIND]; |
||
99 | |||
100 | /** |
||
101 | * The Expr instance used for building this query. |
||
102 | * |
||
103 | * This object includes the query criteria and the "new object" used for |
||
104 | * insert and update queries. |
||
105 | * |
||
106 | * @var Expr $expr |
||
107 | */ |
||
108 | private $expr; |
||
109 | |||
110 | /** |
||
111 | * Construct a Builder |
||
112 | * |
||
113 | * @param string[]|string|null $documentName (optional) an array of document names, the document name, or none |
||
114 | */ |
||
115 | 285 | public function __construct(DocumentManager $dm, $documentName = null) |
|
125 | |||
126 | 1 | public function __clone() |
|
130 | |||
131 | /** |
||
132 | * Add one or more $and clauses to the current query. |
||
133 | * |
||
134 | * You can create a new expression using the {@link Builder::expr()} method. |
||
135 | * |
||
136 | * @see Expr::addAnd() |
||
137 | * @see http://docs.mongodb.org/manual/reference/operator/and/ |
||
138 | * |
||
139 | * @param array|Expr $expression |
||
140 | * @param array|Expr ...$expressions |
||
141 | */ |
||
142 | 4 | public function addAnd($expression, ...$expressions) : self |
|
148 | |||
149 | /** |
||
150 | * Add one or more $nor clauses to the current query. |
||
151 | * |
||
152 | * You can create a new expression using the {@link Builder::expr()} method. |
||
153 | * |
||
154 | * @see Expr::addNor() |
||
155 | * @see http://docs.mongodb.org/manual/reference/operator/nor/ |
||
156 | * |
||
157 | * @param array|Expr $expression |
||
158 | * @param array|Expr ...$expressions |
||
159 | */ |
||
160 | 3 | public function addNor($expression, ...$expressions) : self |
|
166 | |||
167 | /** |
||
168 | * Add one or more $or clauses to the current query. |
||
169 | * |
||
170 | * You can create a new expression using the {@link Builder::expr()} method. |
||
171 | * |
||
172 | * @see Expr::addOr() |
||
173 | * @see http://docs.mongodb.org/manual/reference/operator/or/ |
||
174 | * |
||
175 | * @param array|Expr $expression |
||
176 | * @param array|Expr ...$expressions |
||
177 | */ |
||
178 | 6 | public function addOr($expression, ...$expressions) : self |
|
184 | |||
185 | /** |
||
186 | * Append one or more values to the current array field only if they do not |
||
187 | * already exist in the array. |
||
188 | * |
||
189 | * If the field does not exist, it will be set to an array containing the |
||
190 | * unique value(s) in the argument. If the field is not an array, the query |
||
191 | * will yield an error. |
||
192 | * |
||
193 | * Multiple values may be specified by provided an Expr object and using |
||
194 | * {@link Expr::each()}. |
||
195 | * |
||
196 | * @see Expr::addToSet() |
||
197 | * @see http://docs.mongodb.org/manual/reference/operator/addToSet/ |
||
198 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
199 | * |
||
200 | * @param mixed|Expr $valueOrExpression |
||
201 | */ |
||
202 | 5 | public function addToSet($valueOrExpression) : self |
|
208 | |||
209 | /** |
||
210 | * Specify $all criteria for the current field. |
||
211 | * |
||
212 | * @see Expr::all() |
||
213 | * @see http://docs.mongodb.org/manual/reference/operator/all/ |
||
214 | */ |
||
215 | 3 | public function all(array $values) : self |
|
221 | |||
222 | /** |
||
223 | * Apply a bitwise and operation on the current field. |
||
224 | * |
||
225 | * @see Expr::bitAnd() |
||
226 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
227 | * |
||
228 | * @return $this |
||
229 | */ |
||
230 | 1 | public function bitAnd(int $value) : self |
|
236 | |||
237 | /** |
||
238 | * Apply a bitwise or operation on the current field. |
||
239 | * |
||
240 | * @see Expr::bitOr() |
||
241 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
242 | */ |
||
243 | 1 | public function bitOr(int $value) : self |
|
249 | |||
250 | /** |
||
251 | * Matches documents where all of the bit positions given by the query are |
||
252 | * clear. |
||
253 | * |
||
254 | * @see Expr::bitsAllClear() |
||
255 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/ |
||
256 | * |
||
257 | * @param int|array|Binary $value |
||
258 | */ |
||
259 | 1 | public function bitsAllClear($value) : self |
|
265 | |||
266 | /** |
||
267 | * Matches documents where all of the bit positions given by the query are |
||
268 | * set. |
||
269 | * |
||
270 | * @see Expr::bitsAllSet() |
||
271 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllSet/ |
||
272 | * |
||
273 | * @param int|array|Binary $value |
||
274 | */ |
||
275 | 1 | public function bitsAllSet($value) : self |
|
281 | |||
282 | /** |
||
283 | * Matches documents where any of the bit positions given by the query are |
||
284 | * clear. |
||
285 | * |
||
286 | * @see Expr::bitsAnyClear() |
||
287 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnyClear/ |
||
288 | * |
||
289 | * @param int|array|Binary $value |
||
290 | */ |
||
291 | 1 | public function bitsAnyClear($value) : self |
|
297 | |||
298 | /** |
||
299 | * Matches documents where any of the bit positions given by the query are |
||
300 | * set. |
||
301 | * |
||
302 | * @see Expr::bitsAnySet() |
||
303 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnySet/ |
||
304 | * |
||
305 | * @param int|array|Binary $value |
||
306 | */ |
||
307 | 1 | public function bitsAnySet($value) : self |
|
313 | |||
314 | /** |
||
315 | * Apply a bitwise xor operation on the current field. |
||
316 | * |
||
317 | * @see Expr::bitXor() |
||
318 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
319 | */ |
||
320 | 1 | public function bitXor(int $value) : self |
|
326 | |||
327 | /** |
||
328 | * A boolean flag to enable or disable case sensitive search for $text |
||
329 | * criteria. |
||
330 | * |
||
331 | * This method must be called after text(). |
||
332 | * |
||
333 | * @see Expr::caseSensitive() |
||
334 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
335 | * |
||
336 | * @throws BadMethodCallException If the query does not already have $text criteria. |
||
337 | */ |
||
338 | 1 | public function caseSensitive(bool $caseSensitive) : self |
|
344 | |||
345 | /** |
||
346 | * Associates a comment to any expression taking a query predicate. |
||
347 | * |
||
348 | * @see Expr::comment() |
||
349 | * @see http://docs.mongodb.org/manual/reference/operator/query/comment/ |
||
350 | */ |
||
351 | 1 | public function comment(string $comment) : self |
|
357 | |||
358 | /** |
||
359 | * Change the query type to count. |
||
360 | */ |
||
361 | public function count() : self |
||
367 | |||
368 | /** |
||
369 | * Sets the value of the current field to the current date, either as a date or a timestamp. |
||
370 | * |
||
371 | * @see Expr::currentDate() |
||
372 | * @see http://docs.mongodb.org/manual/reference/operator/currentDate/ |
||
373 | */ |
||
374 | 3 | public function currentDate(string $type = 'date') : self |
|
380 | |||
381 | /** |
||
382 | * Return an array of information about the Builder state for debugging. |
||
383 | * |
||
384 | * The $name parameter may be used to return a specific key from the |
||
385 | * internal $query array property. If omitted, the entire array will be |
||
386 | * returned. |
||
387 | * |
||
388 | * @return mixed |
||
389 | */ |
||
390 | 26 | public function debug(?string $name = null) |
|
394 | |||
395 | /** |
||
396 | * A boolean flag to enable or disable diacritic sensitive search for $text |
||
397 | * criteria. |
||
398 | * |
||
399 | * This method must be called after text(). |
||
400 | * |
||
401 | * @see Builder::diacriticSensitive() |
||
402 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
403 | * |
||
404 | * @throws BadMethodCallException If the query does not already have $text criteria. |
||
405 | */ |
||
406 | 1 | public function diacriticSensitive(bool $diacriticSensitive) : self |
|
412 | |||
413 | /** |
||
414 | * Change the query type to a distinct command. |
||
415 | * |
||
416 | * @see http://docs.mongodb.org/manual/reference/command/distinct/ |
||
417 | */ |
||
418 | 2 | public function distinct(string $field) : self |
|
425 | |||
426 | /** |
||
427 | * Specify $elemMatch criteria for the current field. |
||
428 | * |
||
429 | * You can create a new expression using the {@link Builder::expr()} method. |
||
430 | * |
||
431 | * @see Expr::elemMatch() |
||
432 | * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/ |
||
433 | * |
||
434 | * @param array|Expr $expression |
||
435 | */ |
||
436 | 6 | public function elemMatch($expression) : self |
|
442 | |||
443 | /** |
||
444 | * Specify an equality match for the current field. |
||
445 | * |
||
446 | * @see Expr::equals() |
||
447 | * |
||
448 | * @param mixed $value |
||
449 | */ |
||
450 | 79 | public function equals($value) : self |
|
456 | |||
457 | /** |
||
458 | * Set one or more fields to be excluded from the query projection. |
||
459 | * |
||
460 | * If fields have been selected for inclusion, only the "_id" field may be |
||
461 | * excluded. |
||
462 | * |
||
463 | * @param array|string $fieldName,... |
||
464 | */ |
||
465 | 6 | public function exclude($fieldName = null) : self |
|
479 | |||
480 | /** |
||
481 | * Specify $exists criteria for the current field. |
||
482 | * |
||
483 | * @see Expr::exists() |
||
484 | * @see http://docs.mongodb.org/manual/reference/operator/exists/ |
||
485 | */ |
||
486 | 5 | public function exists(bool $bool) : self |
|
492 | |||
493 | /** |
||
494 | * Create a new Expr instance that can be used as an expression with the Builder |
||
495 | */ |
||
496 | 26 | public function expr() : Expr |
|
503 | |||
504 | /** |
||
505 | * Set the current field to operate on. |
||
506 | */ |
||
507 | 145 | public function field(string $field) : self |
|
514 | |||
515 | /** |
||
516 | * Change the query type to find and optionally set and change the class being queried. |
||
517 | */ |
||
518 | 13 | public function find(?string $documentName = null) : self |
|
525 | |||
526 | 1 | public function findAndRemove(?string $documentName = null) : self |
|
533 | |||
534 | 13 | public function findAndUpdate(?string $documentName = null) : self |
|
541 | |||
542 | /** |
||
543 | * Add $geoIntersects criteria with a GeoJSON geometry to the query. |
||
544 | * |
||
545 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
546 | * geometry's JSON representation. |
||
547 | * |
||
548 | * @see Expr::geoIntersects() |
||
549 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
550 | * |
||
551 | * @param array|Geometry $geometry |
||
552 | */ |
||
553 | 1 | public function geoIntersects($geometry) : self |
|
559 | |||
560 | /** |
||
561 | * Add $geoWithin criteria with a GeoJSON geometry to the query. |
||
562 | * |
||
563 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
564 | * geometry's JSON representation. |
||
565 | * |
||
566 | * @see Expr::geoWithin() |
||
567 | * @see http://docs.mongodb.org/manual/reference/operator/geoWithin/ |
||
568 | * |
||
569 | * @param array|Geometry $geometry |
||
570 | */ |
||
571 | 1 | public function geoWithin($geometry) : self |
|
577 | |||
578 | /** |
||
579 | * Add $geoWithin criteria with a $box shape to the query. |
||
580 | * |
||
581 | * A rectangular polygon will be constructed from a pair of coordinates |
||
582 | * corresponding to the bottom left and top right corners. |
||
583 | * |
||
584 | * Note: the $box operator only supports legacy coordinate pairs and 2d |
||
585 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
586 | * |
||
587 | * @see Expr::geoWithinBox() |
||
588 | * @see http://docs.mongodb.org/manual/reference/operator/box/ |
||
589 | */ |
||
590 | 1 | public function geoWithinBox(float $x1, float $y1, float $x2, float $y2) : self |
|
596 | |||
597 | /** |
||
598 | * Add $geoWithin criteria with a $center shape to the query. |
||
599 | * |
||
600 | * Note: the $center operator only supports legacy coordinate pairs and 2d |
||
601 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
602 | * |
||
603 | * @see Expr::geoWithinCenter() |
||
604 | * @see http://docs.mongodb.org/manual/reference/operator/center/ |
||
605 | */ |
||
606 | 1 | public function geoWithinCenter(float $x, float $y, float $radius) : self |
|
612 | |||
613 | /** |
||
614 | * Add $geoWithin criteria with a $centerSphere shape to the query. |
||
615 | * |
||
616 | * Note: the $centerSphere operator supports both 2d and 2dsphere indexes. |
||
617 | * |
||
618 | * @see Expr::geoWithinCenterSphere() |
||
619 | * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/ |
||
620 | */ |
||
621 | 1 | public function geoWithinCenterSphere(float $x, float $y, float $radius) : self |
|
627 | |||
628 | /** |
||
629 | * Add $geoWithin criteria with a $polygon shape to the query. |
||
630 | * |
||
631 | * Point coordinates are in x, y order (easting, northing for projected |
||
632 | * coordinates, longitude, latitude for geographic coordinates). |
||
633 | * |
||
634 | * The last point coordinate is implicitly connected with the first. |
||
635 | * |
||
636 | * Note: the $polygon operator only supports legacy coordinate pairs and 2d |
||
637 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
638 | * |
||
639 | * @see Expr::geoWithinPolygon() |
||
640 | * @see http://docs.mongodb.org/manual/reference/operator/polygon/ |
||
641 | * |
||
642 | * @param array $point1 First point of the polygon |
||
643 | * @param array $point2 Second point of the polygon |
||
644 | * @param array $point3 Third point of the polygon |
||
645 | * @param array ...$points Additional points of the polygon |
||
646 | */ |
||
647 | 1 | public function geoWithinPolygon($point1, $point2, $point3, ...$points) : self |
|
653 | |||
654 | /** |
||
655 | * Return the expression's "new object". |
||
656 | * |
||
657 | * @see Expr::getNewObj() |
||
658 | */ |
||
659 | 13 | public function getNewObj() : array |
|
663 | |||
664 | /** |
||
665 | * Gets the Query executable. |
||
666 | */ |
||
667 | 158 | public function getQuery(array $options = []) : Query |
|
723 | |||
724 | /** |
||
725 | * Return the expression's query criteria. |
||
726 | * |
||
727 | * @see Expr::getQuery() |
||
728 | */ |
||
729 | 32 | public function getQueryArray() : array |
|
733 | |||
734 | /** |
||
735 | * Get the type of this query. |
||
736 | */ |
||
737 | public function getType() : int |
||
741 | |||
742 | /** |
||
743 | * Specify $gt criteria for the current field. |
||
744 | * |
||
745 | * @see Expr::gt() |
||
746 | * @see http://docs.mongodb.org/manual/reference/operator/gt/ |
||
747 | * |
||
748 | * @param mixed $value |
||
749 | */ |
||
750 | 2 | public function gt($value) : self |
|
756 | |||
757 | /** |
||
758 | * Specify $gte criteria for the current field. |
||
759 | * |
||
760 | * @see Expr::gte() |
||
761 | * @see http://docs.mongodb.org/manual/reference/operator/gte/ |
||
762 | * |
||
763 | * @param mixed $value |
||
764 | */ |
||
765 | 2 | public function gte($value) : self |
|
771 | |||
772 | /** |
||
773 | * Set the index hint for the query. |
||
774 | * |
||
775 | * @param array|string $index |
||
776 | */ |
||
777 | public function hint($index) : self |
||
783 | |||
784 | 17 | public function hydrate(bool $bool = true) : self |
|
790 | |||
791 | /** |
||
792 | * Set the immortal cursor flag. |
||
793 | */ |
||
794 | public function immortal(bool $bool = true) : self |
||
800 | |||
801 | /** |
||
802 | * Specify $in criteria for the current field. |
||
803 | * |
||
804 | * @see Expr::in() |
||
805 | * @see http://docs.mongodb.org/manual/reference/operator/in/ |
||
806 | */ |
||
807 | 24 | public function in(array $values) : self |
|
813 | |||
814 | /** |
||
815 | * Increment the current field. |
||
816 | * |
||
817 | * If the field does not exist, it will be set to this value. |
||
818 | * |
||
819 | * @see Expr::inc() |
||
820 | * @see http://docs.mongodb.org/manual/reference/operator/inc/ |
||
821 | * |
||
822 | * @param float|int $value |
||
823 | */ |
||
824 | 6 | public function inc($value) : self |
|
830 | |||
831 | 6 | public function includesReferenceTo(object $document) : self |
|
837 | |||
838 | 1 | public function insert(?string $documentName = null) : self |
|
845 | |||
846 | /** |
||
847 | * Set the $language option for $text criteria. |
||
848 | * |
||
849 | * This method must be called after text(). |
||
850 | * |
||
851 | * @see Expr::language() |
||
852 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
853 | */ |
||
854 | 1 | public function language(string $language) : self |
|
860 | |||
861 | /** |
||
862 | * Set the limit for the query. |
||
863 | * |
||
864 | * This is only relevant for find queries and count commands. |
||
865 | * |
||
866 | * @see Query::prepareCursor() |
||
867 | */ |
||
868 | 3 | public function limit(int $limit) : self |
|
874 | |||
875 | /** |
||
876 | * Specify $lt criteria for the current field. |
||
877 | * |
||
878 | * @see Expr::lte() |
||
879 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
880 | * |
||
881 | * @param mixed $value |
||
882 | */ |
||
883 | public function lt($value) : self |
||
889 | |||
890 | /** |
||
891 | * Specify $lte criteria for the current field. |
||
892 | * |
||
893 | * @see Expr::lte() |
||
894 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
895 | * |
||
896 | * @param mixed $value |
||
897 | */ |
||
898 | public function lte($value) : self |
||
904 | |||
905 | /** |
||
906 | * Updates the value of the field to a specified value if the specified value is greater than the current value of the field. |
||
907 | * |
||
908 | * @see Expr::max() |
||
909 | * @see http://docs.mongodb.org/manual/reference/operator/update/max/ |
||
910 | * |
||
911 | * @param mixed $value |
||
912 | */ |
||
913 | 1 | public function max($value) : self |
|
919 | |||
920 | /** |
||
921 | * Specifies a cumulative time limit in milliseconds for processing operations on a cursor. |
||
922 | */ |
||
923 | public function maxTimeMS(int $ms) : self |
||
929 | |||
930 | /** |
||
931 | * Updates the value of the field to a specified value if the specified value is less than the current value of the field. |
||
932 | * |
||
933 | * @see Expr::min() |
||
934 | * @see http://docs.mongodb.org/manual/reference/operator/update/min/ |
||
935 | * |
||
936 | * @param mixed $value |
||
937 | */ |
||
938 | 1 | public function min($value) : self |
|
944 | |||
945 | /** |
||
946 | * Specify $mod criteria for the current field. |
||
947 | * |
||
948 | * @see Expr::mod() |
||
949 | * @see http://docs.mongodb.org/manual/reference/operator/mod/ |
||
950 | * |
||
951 | * @param float|int $divisor |
||
952 | * @param float|int $remainder |
||
953 | */ |
||
954 | 1 | public function mod($divisor, $remainder = 0) : self |
|
960 | |||
961 | /** |
||
962 | * Multiply the current field. |
||
963 | * |
||
964 | * If the field does not exist, it will be set to 0. |
||
965 | * |
||
966 | * @see Expr::mul() |
||
967 | * @see http://docs.mongodb.org/manual/reference/operator/mul/ |
||
968 | * |
||
969 | * @param float|int $value |
||
970 | */ |
||
971 | 1 | public function mul($value) : self |
|
977 | |||
978 | /** |
||
979 | * Add $near criteria to the query. |
||
980 | * |
||
981 | * A GeoJSON point may be provided as the first and only argument for |
||
982 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
983 | * an array corresponding to the point's JSON representation. |
||
984 | * |
||
985 | * @see Expr::near() |
||
986 | * @see http://docs.mongodb.org/manual/reference/operator/near/ |
||
987 | * |
||
988 | * @param float|array|Point $x |
||
989 | * @param float $y |
||
990 | */ |
||
991 | 1 | public function near($x, $y = null) : self |
|
997 | |||
998 | /** |
||
999 | * Add $nearSphere criteria to the query. |
||
1000 | * |
||
1001 | * A GeoJSON point may be provided as the first and only argument for |
||
1002 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
1003 | * an array corresponding to the point's JSON representation. |
||
1004 | * |
||
1005 | * @see Expr::nearSphere() |
||
1006 | * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/ |
||
1007 | * |
||
1008 | * @param float|array|Point $x |
||
1009 | * @param float $y |
||
1010 | */ |
||
1011 | 1 | public function nearSphere($x, $y = null) : self |
|
1017 | |||
1018 | /** |
||
1019 | * Negates an expression for the current field. |
||
1020 | * |
||
1021 | * You can create a new expression using the {@link Builder::expr()} method. |
||
1022 | * |
||
1023 | * @see Expr::not() |
||
1024 | * @see http://docs.mongodb.org/manual/reference/operator/not/ |
||
1025 | * |
||
1026 | * @param array|Expr $expression |
||
1027 | */ |
||
1028 | 3 | public function not($expression) : self |
|
1034 | |||
1035 | /** |
||
1036 | * Specify $ne criteria for the current field. |
||
1037 | * |
||
1038 | * @see Expr::notEqual() |
||
1039 | * @see http://docs.mongodb.org/manual/reference/operator/ne/ |
||
1040 | * |
||
1041 | * @param mixed $value |
||
1042 | */ |
||
1043 | 4 | public function notEqual($value) : self |
|
1049 | |||
1050 | /** |
||
1051 | * Specify $nin criteria for the current field. |
||
1052 | * |
||
1053 | * @see Expr::notIn() |
||
1054 | * @see http://docs.mongodb.org/manual/reference/operator/nin/ |
||
1055 | * |
||
1056 | * @param array $values |
||
1057 | */ |
||
1058 | 4 | public function notIn(array $values) : self |
|
1064 | |||
1065 | /** |
||
1066 | * Remove the first element from the current array field. |
||
1067 | * |
||
1068 | * @see Expr::popFirst() |
||
1069 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
1070 | */ |
||
1071 | 3 | public function popFirst() : self |
|
1077 | |||
1078 | /** |
||
1079 | * Remove the last element from the current array field. |
||
1080 | * |
||
1081 | * @see Expr::popLast() |
||
1082 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
1083 | */ |
||
1084 | 2 | public function popLast() : self |
|
1090 | |||
1091 | /** |
||
1092 | * Use a primer to eagerly load all references in the current field. |
||
1093 | * |
||
1094 | * If $primer is true or a callable is provided, referenced documents for |
||
1095 | * this field will loaded into UnitOfWork immediately after the query is |
||
1096 | * executed. This will avoid multiple queries due to lazy initialization of |
||
1097 | * Proxy objects. |
||
1098 | * |
||
1099 | * If $primer is false, no priming will take place. That is also the default |
||
1100 | * behavior. |
||
1101 | * |
||
1102 | * If a custom callable is used, its signature should conform to the default |
||
1103 | * Closure defined in {@link ReferencePrimer::__construct()}. |
||
1104 | * |
||
1105 | * @param bool|callable $primer |
||
1106 | * |
||
1107 | * @throws InvalidArgumentException If $primer is not boolean or callable. |
||
1108 | */ |
||
1109 | 22 | public function prime($primer = true) : self |
|
1125 | |||
1126 | /** |
||
1127 | * Remove all elements matching the given value or expression from the |
||
1128 | * current array field. |
||
1129 | * |
||
1130 | * @see Expr::pull() |
||
1131 | * @see http://docs.mongodb.org/manual/reference/operator/pull/ |
||
1132 | * |
||
1133 | * @param mixed|Expr $valueOrExpression |
||
1134 | */ |
||
1135 | 1 | public function pull($valueOrExpression) : self |
|
1141 | |||
1142 | /** |
||
1143 | * Remove all elements matching any of the given values from the current |
||
1144 | * array field. |
||
1145 | * |
||
1146 | * @see Expr::pullAll() |
||
1147 | * @see http://docs.mongodb.org/manual/reference/operator/pullAll/ |
||
1148 | */ |
||
1149 | 1 | public function pullAll(array $values) : self |
|
1155 | |||
1156 | /** |
||
1157 | * Append one or more values to the current array field. |
||
1158 | * |
||
1159 | * If the field does not exist, it will be set to an array containing the |
||
1160 | * value(s) in the argument. If the field is not an array, the query |
||
1161 | * will yield an error. |
||
1162 | * |
||
1163 | * Multiple values may be specified by providing an Expr object and using |
||
1164 | * {@link Expr::each()}. {@link Expr::slice()} and {@link Expr::sort()} may |
||
1165 | * also be used to limit and order array elements, respectively. |
||
1166 | * |
||
1167 | * @see Expr::push() |
||
1168 | * @see http://docs.mongodb.org/manual/reference/operator/push/ |
||
1169 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
1170 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
1171 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
1172 | * |
||
1173 | * @param mixed|Expr $valueOrExpression |
||
1174 | */ |
||
1175 | 6 | public function push($valueOrExpression) : self |
|
1181 | |||
1182 | /** |
||
1183 | * Specify $gte and $lt criteria for the current field. |
||
1184 | * |
||
1185 | * This method is shorthand for specifying $gte criteria on the lower bound |
||
1186 | * and $lt criteria on the upper bound. The upper bound is not inclusive. |
||
1187 | * |
||
1188 | * @see Expr::range() |
||
1189 | * |
||
1190 | * @param mixed $start |
||
1191 | * @param mixed $end |
||
1192 | */ |
||
1193 | 3 | public function range($start, $end) : self |
|
1199 | |||
1200 | 2 | public function readOnly(bool $bool = true) : self |
|
1206 | |||
1207 | 10 | public function references(object $document) : self |
|
1213 | |||
1214 | 5 | public function refresh(bool $bool = true) : self |
|
1220 | |||
1221 | 1 | public function remove(?string $documentName = null) : self |
|
1228 | |||
1229 | /** |
||
1230 | * Rename the current field. |
||
1231 | * |
||
1232 | * @see Expr::rename() |
||
1233 | * @see http://docs.mongodb.org/manual/reference/operator/rename/ |
||
1234 | */ |
||
1235 | public function rename(string $name) : self |
||
1241 | |||
1242 | 4 | public function returnNew(bool $bool = true) : self |
|
1249 | |||
1250 | /** |
||
1251 | * Set one or more fields to be included in the query projection. |
||
1252 | * |
||
1253 | * @param array|string $fieldName,... |
||
1254 | */ |
||
1255 | 19 | public function select($fieldName = null) : self |
|
1269 | |||
1270 | /** |
||
1271 | * Select only matching embedded documents in an array field for the query |
||
1272 | * projection. |
||
1273 | * |
||
1274 | * @see http://docs.mongodb.org/manual/reference/projection/elemMatch/ |
||
1275 | * |
||
1276 | * @param array|Expr $expression |
||
1277 | */ |
||
1278 | 2 | public function selectElemMatch(string $fieldName, $expression) : self |
|
1287 | |||
1288 | /** |
||
1289 | * Select a metadata field for the query projection. |
||
1290 | * |
||
1291 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/ |
||
1292 | */ |
||
1293 | 3 | public function selectMeta(string $fieldName, string $metaDataKeyword) : self |
|
1299 | |||
1300 | /** |
||
1301 | * Select a slice of an array field for the query projection. |
||
1302 | * |
||
1303 | * The $countOrSkip parameter has two very different meanings, depending on |
||
1304 | * whether or not $limit is provided. See the MongoDB documentation for more |
||
1305 | * information. |
||
1306 | * |
||
1307 | * @see http://docs.mongodb.org/manual/reference/projection/slice/ |
||
1308 | */ |
||
1309 | 3 | public function selectSlice(string $fieldName, int $countOrSkip, ?int $limit = null) : self |
|
1319 | |||
1320 | /** |
||
1321 | * Set the current field to a value. |
||
1322 | * |
||
1323 | * This is only relevant for insert, update, or findAndUpdate queries. For |
||
1324 | * update and findAndUpdate queries, the $atomic parameter will determine |
||
1325 | * whether or not a $set operator is used. |
||
1326 | * |
||
1327 | * @see Expr::set() |
||
1328 | * @see http://docs.mongodb.org/manual/reference/operator/set/ |
||
1329 | * |
||
1330 | * @param mixed $value |
||
1331 | */ |
||
1332 | 16 | public function set($value, bool $atomic = true) : self |
|
1338 | |||
1339 | /** |
||
1340 | * Set the expression's "new object". |
||
1341 | * |
||
1342 | * @see Expr::setNewObj() |
||
1343 | */ |
||
1344 | 1 | public function setNewObj(array $newObj) : self |
|
1350 | |||
1351 | /** |
||
1352 | * Set the current field to the value if the document is inserted in an |
||
1353 | * upsert operation. |
||
1354 | * |
||
1355 | * If an update operation with upsert: true results in an insert of a |
||
1356 | * document, then $setOnInsert assigns the specified values to the fields in |
||
1357 | * the document. If the update operation does not result in an insert, |
||
1358 | * $setOnInsert does nothing. |
||
1359 | * |
||
1360 | * @see Expr::setOnInsert() |
||
1361 | * @see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ |
||
1362 | * |
||
1363 | * @param mixed $value |
||
1364 | */ |
||
1365 | 2 | public function setOnInsert($value) : self |
|
1371 | |||
1372 | /** |
||
1373 | * Set the read preference for the query. |
||
1374 | * |
||
1375 | * This is only relevant for read-only queries and commands. |
||
1376 | * |
||
1377 | * @see http://docs.mongodb.org/manual/core/read-preference/ |
||
1378 | */ |
||
1379 | 6 | public function setReadPreference(ReadPreference $readPreference) : self |
|
1385 | |||
1386 | 1 | public function setRewindable(bool $rewindable = true) : self |
|
1387 | { |
||
1388 | 1 | $this->rewindable = $rewindable; |
|
1389 | |||
1390 | 1 | return $this; |
|
1391 | } |
||
1392 | |||
1393 | /** |
||
1394 | * Set the expression's query criteria. |
||
1395 | * |
||
1396 | * @see Expr::setQuery() |
||
1397 | */ |
||
1398 | 19 | public function setQueryArray(array $query) : self |
|
1404 | |||
1405 | /** |
||
1406 | * Specify $size criteria for the current field. |
||
1407 | * |
||
1408 | * @see Expr::size() |
||
1409 | * @see http://docs.mongodb.org/manual/reference/operator/size/ |
||
1410 | */ |
||
1411 | 1 | public function size(int $size) : self |
|
1417 | |||
1418 | /** |
||
1419 | * Set the skip for the query cursor. |
||
1420 | * |
||
1421 | * This is only relevant for find queries, or mapReduce queries that store |
||
1422 | * results in an output collection and return a cursor. |
||
1423 | * |
||
1424 | * @see Query::prepareCursor() |
||
1425 | */ |
||
1426 | public function skip(int $skip) : self |
||
1432 | |||
1433 | /** |
||
1434 | * Set the snapshot cursor flag. |
||
1435 | */ |
||
1436 | public function snapshot(bool $bool = true) : self |
||
1442 | |||
1443 | /** |
||
1444 | * Set one or more field/order pairs on which to sort the query. |
||
1445 | * |
||
1446 | * If sorting by multiple fields, the first argument should be an array of |
||
1447 | * field name (key) and order (value) pairs. |
||
1448 | * |
||
1449 | * @param array|string $fieldName Field name or array of field/order pairs |
||
1450 | * @param int|string $order Field order (if one field is specified) |
||
1451 | */ |
||
1452 | 30 | public function sort($fieldName, $order = 1) : self |
|
1469 | |||
1470 | /** |
||
1471 | * Specify a projected metadata field on which to sort the query. |
||
1472 | * |
||
1473 | * Sort order is not configurable for metadata fields. Sorting by a metadata |
||
1474 | * field requires the same field and $meta expression to exist in the |
||
1475 | * projection document. This method will call {@link Builder::selectMeta()} |
||
1476 | * if the field is not already set in the projection. |
||
1477 | * |
||
1478 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/#sort |
||
1479 | */ |
||
1480 | 3 | public function sortMeta(string $fieldName, string $metaDataKeyword) : self |
|
1494 | |||
1495 | /** |
||
1496 | * Specify $text criteria for the current field. |
||
1497 | * |
||
1498 | * The $language option may be set with {@link Builder::language()}. |
||
1499 | * |
||
1500 | * @see Expr::text() |
||
1501 | * @see http://docs.mongodb.org/master/reference/operator/query/text/ |
||
1502 | */ |
||
1503 | 1 | public function text(string $search) : self |
|
1509 | |||
1510 | /** |
||
1511 | * Specify $type criteria for the current field. |
||
1512 | * |
||
1513 | * @see Expr::type() |
||
1514 | * @see http://docs.mongodb.org/manual/reference/operator/type/ |
||
1515 | * |
||
1516 | * @param int|string $type |
||
1517 | */ |
||
1518 | 2 | public function type($type) : self |
|
1524 | |||
1525 | /** |
||
1526 | * Unset the current field. |
||
1527 | * |
||
1528 | * The field will be removed from the document (not set to null). |
||
1529 | * |
||
1530 | * @see Expr::unsetField() |
||
1531 | * @see http://docs.mongodb.org/manual/reference/operator/unset/ |
||
1532 | */ |
||
1533 | 4 | public function unsetField() : self |
|
1539 | |||
1540 | 23 | public function updateOne(?string $documentName = null) : self |
|
1548 | |||
1549 | 4 | public function updateMany(?string $documentName = null) : self |
|
1557 | |||
1558 | /** |
||
1559 | * Set the "upsert" option for an update or findAndUpdate query. |
||
1560 | */ |
||
1561 | 7 | public function upsert(bool $bool = true) : self |
|
1567 | |||
1568 | /** |
||
1569 | * Specify a JavaScript expression to use for matching documents. |
||
1570 | * |
||
1571 | * @see Expr::where() |
||
1572 | * @see http://docs.mongodb.org/manual/reference/operator/where/ |
||
1573 | * |
||
1574 | * @param string|Javascript $javascript |
||
1575 | */ |
||
1576 | 3 | public function where($javascript) : self |
|
1582 | |||
1583 | /** |
||
1584 | * Get Discriminator Values |
||
1585 | * |
||
1586 | * @param string[] $classNames |
||
1587 | * |
||
1588 | * @throws InvalidArgumentException If the number of found collections > 1. |
||
1589 | */ |
||
1590 | 2 | private function getDiscriminatorValues($classNames) : array |
|
1606 | |||
1607 | /** |
||
1608 | * @param string[]|string|null $documentName an array of document names or just one. |
||
1609 | */ |
||
1610 | 284 | private function setDocumentName($documentName) |
|
1638 | } |
||
1639 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.