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 | /** |
||
84 | * The Collection instance. |
||
85 | * |
||
86 | * @var Collection |
||
87 | */ |
||
88 | private $collection; |
||
89 | |||
90 | /** |
||
91 | * Array containing the query data. |
||
92 | * |
||
93 | * @var array |
||
94 | */ |
||
95 | private $query = ['type' => Query::TYPE_FIND]; |
||
96 | |||
97 | /** |
||
98 | * The Expr instance used for building this query. |
||
99 | * |
||
100 | * This object includes the query criteria and the "new object" used for |
||
101 | * insert and update queries. |
||
102 | * |
||
103 | * @var Expr $expr |
||
104 | */ |
||
105 | private $expr; |
||
106 | |||
107 | /** |
||
108 | * Construct a Builder |
||
109 | * |
||
110 | * @param string[]|string|null $documentName (optional) an array of document names, the document name, or none |
||
111 | */ |
||
112 | 282 | public function __construct(DocumentManager $dm, $documentName = null) |
|
122 | |||
123 | 1 | public function __clone() |
|
127 | |||
128 | /** |
||
129 | * Add one or more $and clauses to the current query. |
||
130 | * |
||
131 | * You can create a new expression using the {@link Builder::expr()} method. |
||
132 | * |
||
133 | * @see Expr::addAnd() |
||
134 | * @see http://docs.mongodb.org/manual/reference/operator/and/ |
||
135 | * |
||
136 | * @param array|Expr $expression |
||
137 | * @param array|Expr ...$expressions |
||
138 | */ |
||
139 | 4 | public function addAnd($expression, ...$expressions) : self |
|
145 | |||
146 | /** |
||
147 | * Add one or more $nor clauses to the current query. |
||
148 | * |
||
149 | * You can create a new expression using the {@link Builder::expr()} method. |
||
150 | * |
||
151 | * @see Expr::addNor() |
||
152 | * @see http://docs.mongodb.org/manual/reference/operator/nor/ |
||
153 | * |
||
154 | * @param array|Expr $expression |
||
155 | * @param array|Expr ...$expressions |
||
156 | */ |
||
157 | 3 | public function addNor($expression, ...$expressions) : self |
|
163 | |||
164 | /** |
||
165 | * Add one or more $or clauses to the current query. |
||
166 | * |
||
167 | * You can create a new expression using the {@link Builder::expr()} method. |
||
168 | * |
||
169 | * @see Expr::addOr() |
||
170 | * @see http://docs.mongodb.org/manual/reference/operator/or/ |
||
171 | * |
||
172 | * @param array|Expr $expression |
||
173 | * @param array|Expr ...$expressions |
||
174 | */ |
||
175 | 6 | public function addOr($expression, ...$expressions) : self |
|
181 | |||
182 | /** |
||
183 | * Append one or more values to the current array field only if they do not |
||
184 | * already exist in the array. |
||
185 | * |
||
186 | * If the field does not exist, it will be set to an array containing the |
||
187 | * unique value(s) in the argument. If the field is not an array, the query |
||
188 | * will yield an error. |
||
189 | * |
||
190 | * Multiple values may be specified by provided an Expr object and using |
||
191 | * {@link Expr::each()}. |
||
192 | * |
||
193 | * @see Expr::addToSet() |
||
194 | * @see http://docs.mongodb.org/manual/reference/operator/addToSet/ |
||
195 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
196 | * |
||
197 | * @param mixed|Expr $valueOrExpression |
||
198 | */ |
||
199 | 5 | public function addToSet($valueOrExpression) : self |
|
205 | |||
206 | /** |
||
207 | * Specify $all criteria for the current field. |
||
208 | * |
||
209 | * @see Expr::all() |
||
210 | * @see http://docs.mongodb.org/manual/reference/operator/all/ |
||
211 | */ |
||
212 | 3 | public function all(array $values) : self |
|
218 | |||
219 | /** |
||
220 | * Apply a bitwise and operation on the current field. |
||
221 | * |
||
222 | * @see Expr::bitAnd() |
||
223 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
224 | * |
||
225 | * @return $this |
||
226 | */ |
||
227 | 1 | public function bitAnd(int $value) : self |
|
233 | |||
234 | /** |
||
235 | * Apply a bitwise or operation on the current field. |
||
236 | * |
||
237 | * @see Expr::bitOr() |
||
238 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
239 | */ |
||
240 | 1 | public function bitOr(int $value) : self |
|
246 | |||
247 | /** |
||
248 | * Matches documents where all of the bit positions given by the query are |
||
249 | * clear. |
||
250 | * |
||
251 | * @see Expr::bitsAllClear() |
||
252 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/ |
||
253 | * |
||
254 | * @param int|array|Binary $value |
||
255 | */ |
||
256 | 1 | public function bitsAllClear($value) : self |
|
262 | |||
263 | /** |
||
264 | * Matches documents where all of the bit positions given by the query are |
||
265 | * set. |
||
266 | * |
||
267 | * @see Expr::bitsAllSet() |
||
268 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllSet/ |
||
269 | * |
||
270 | * @param int|array|Binary $value |
||
271 | */ |
||
272 | 1 | public function bitsAllSet($value) : self |
|
278 | |||
279 | /** |
||
280 | * Matches documents where any of the bit positions given by the query are |
||
281 | * clear. |
||
282 | * |
||
283 | * @see Expr::bitsAnyClear() |
||
284 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnyClear/ |
||
285 | * |
||
286 | * @param int|array|Binary $value |
||
287 | */ |
||
288 | 1 | public function bitsAnyClear($value) : self |
|
294 | |||
295 | /** |
||
296 | * Matches documents where any of the bit positions given by the query are |
||
297 | * set. |
||
298 | * |
||
299 | * @see Expr::bitsAnySet() |
||
300 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnySet/ |
||
301 | * |
||
302 | * @param int|array|Binary $value |
||
303 | */ |
||
304 | 1 | public function bitsAnySet($value) : self |
|
310 | |||
311 | /** |
||
312 | * Apply a bitwise xor operation on the current field. |
||
313 | * |
||
314 | * @see Expr::bitXor() |
||
315 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
316 | */ |
||
317 | 1 | public function bitXor(int $value) : self |
|
323 | |||
324 | /** |
||
325 | * A boolean flag to enable or disable case sensitive search for $text |
||
326 | * criteria. |
||
327 | * |
||
328 | * This method must be called after text(). |
||
329 | * |
||
330 | * @see Expr::caseSensitive() |
||
331 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
332 | * |
||
333 | * @throws BadMethodCallException If the query does not already have $text criteria. |
||
334 | */ |
||
335 | 1 | public function caseSensitive(bool $caseSensitive) : self |
|
341 | |||
342 | /** |
||
343 | * Associates a comment to any expression taking a query predicate. |
||
344 | * |
||
345 | * @see Expr::comment() |
||
346 | * @see http://docs.mongodb.org/manual/reference/operator/query/comment/ |
||
347 | */ |
||
348 | 1 | public function comment(string $comment) : self |
|
354 | |||
355 | /** |
||
356 | * Change the query type to count. |
||
357 | */ |
||
358 | public function count() : self |
||
364 | |||
365 | /** |
||
366 | * Sets the value of the current field to the current date, either as a date or a timestamp. |
||
367 | * |
||
368 | * @see Expr::currentDate() |
||
369 | * @see http://docs.mongodb.org/manual/reference/operator/currentDate/ |
||
370 | */ |
||
371 | 3 | public function currentDate(string $type = 'date') : self |
|
377 | |||
378 | /** |
||
379 | * Return an array of information about the Builder state for debugging. |
||
380 | * |
||
381 | * The $name parameter may be used to return a specific key from the |
||
382 | * internal $query array property. If omitted, the entire array will be |
||
383 | * returned. |
||
384 | * |
||
385 | * @return mixed |
||
386 | */ |
||
387 | 26 | public function debug(?string $name = null) |
|
391 | |||
392 | /** |
||
393 | * A boolean flag to enable or disable diacritic sensitive search for $text |
||
394 | * criteria. |
||
395 | * |
||
396 | * This method must be called after text(). |
||
397 | * |
||
398 | * @see Builder::diacriticSensitive() |
||
399 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
400 | * |
||
401 | * @throws BadMethodCallException If the query does not already have $text criteria. |
||
402 | */ |
||
403 | 1 | public function diacriticSensitive(bool $diacriticSensitive) : self |
|
409 | |||
410 | /** |
||
411 | * Change the query type to a distinct command. |
||
412 | * |
||
413 | * @see http://docs.mongodb.org/manual/reference/command/distinct/ |
||
414 | */ |
||
415 | 2 | public function distinct(string $field) : self |
|
422 | |||
423 | /** |
||
424 | * Specify $elemMatch criteria for the current field. |
||
425 | * |
||
426 | * You can create a new expression using the {@link Builder::expr()} method. |
||
427 | * |
||
428 | * @see Expr::elemMatch() |
||
429 | * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/ |
||
430 | * |
||
431 | * @param array|Expr $expression |
||
432 | */ |
||
433 | 6 | public function elemMatch($expression) : self |
|
439 | |||
440 | /** |
||
441 | * Specify an equality match for the current field. |
||
442 | * |
||
443 | * @see Expr::equals() |
||
444 | * |
||
445 | * @param mixed $value |
||
446 | */ |
||
447 | 79 | public function equals($value) : self |
|
453 | |||
454 | /** |
||
455 | * Set one or more fields to be excluded from the query projection. |
||
456 | * |
||
457 | * If fields have been selected for inclusion, only the "_id" field may be |
||
458 | * excluded. |
||
459 | * |
||
460 | * @param array|string $fieldName,... |
||
461 | */ |
||
462 | 6 | public function exclude($fieldName = null) : self |
|
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 | */ |
||
483 | 5 | public function exists(bool $bool) : self |
|
489 | |||
490 | /** |
||
491 | * Create a new Expr instance that can be used as an expression with the Builder |
||
492 | */ |
||
493 | 26 | public function expr() : Expr |
|
500 | |||
501 | /** |
||
502 | * Set the current field to operate on. |
||
503 | */ |
||
504 | 145 | public function field(string $field) : self |
|
511 | |||
512 | /** |
||
513 | * Change the query type to find and optionally set and change the class being queried. |
||
514 | */ |
||
515 | 13 | public function find(?string $documentName = null) : self |
|
522 | |||
523 | 1 | public function findAndRemove(?string $documentName = null) : self |
|
530 | |||
531 | 13 | public function findAndUpdate(?string $documentName = null) : self |
|
538 | |||
539 | /** |
||
540 | * Add $geoIntersects criteria with a GeoJSON geometry to the query. |
||
541 | * |
||
542 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
543 | * geometry's JSON representation. |
||
544 | * |
||
545 | * @see Expr::geoIntersects() |
||
546 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
547 | * |
||
548 | * @param array|Geometry $geometry |
||
549 | */ |
||
550 | 1 | public function geoIntersects($geometry) : self |
|
556 | |||
557 | /** |
||
558 | * Add $geoWithin criteria with a GeoJSON geometry to the query. |
||
559 | * |
||
560 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
561 | * geometry's JSON representation. |
||
562 | * |
||
563 | * @see Expr::geoWithin() |
||
564 | * @see http://docs.mongodb.org/manual/reference/operator/geoWithin/ |
||
565 | * |
||
566 | * @param array|Geometry $geometry |
||
567 | */ |
||
568 | 1 | public function geoWithin($geometry) : self |
|
574 | |||
575 | /** |
||
576 | * Add $geoWithin criteria with a $box shape to the query. |
||
577 | * |
||
578 | * A rectangular polygon will be constructed from a pair of coordinates |
||
579 | * corresponding to the bottom left and top right corners. |
||
580 | * |
||
581 | * Note: the $box operator only supports legacy coordinate pairs and 2d |
||
582 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
583 | * |
||
584 | * @see Expr::geoWithinBox() |
||
585 | * @see http://docs.mongodb.org/manual/reference/operator/box/ |
||
586 | */ |
||
587 | 1 | public function geoWithinBox(float $x1, float $y1, float $x2, float $y2) : self |
|
593 | |||
594 | /** |
||
595 | * Add $geoWithin criteria with a $center shape to the query. |
||
596 | * |
||
597 | * Note: the $center operator only supports legacy coordinate pairs and 2d |
||
598 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
599 | * |
||
600 | * @see Expr::geoWithinCenter() |
||
601 | * @see http://docs.mongodb.org/manual/reference/operator/center/ |
||
602 | */ |
||
603 | 1 | public function geoWithinCenter(float $x, float $y, float $radius) : self |
|
609 | |||
610 | /** |
||
611 | * Add $geoWithin criteria with a $centerSphere shape to the query. |
||
612 | * |
||
613 | * Note: the $centerSphere operator supports both 2d and 2dsphere indexes. |
||
614 | * |
||
615 | * @see Expr::geoWithinCenterSphere() |
||
616 | * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/ |
||
617 | */ |
||
618 | 1 | public function geoWithinCenterSphere(float $x, float $y, float $radius) : self |
|
624 | |||
625 | /** |
||
626 | * Add $geoWithin criteria with a $polygon shape to the query. |
||
627 | * |
||
628 | * Point coordinates are in x, y order (easting, northing for projected |
||
629 | * coordinates, longitude, latitude for geographic coordinates). |
||
630 | * |
||
631 | * The last point coordinate is implicitly connected with the first. |
||
632 | * |
||
633 | * Note: the $polygon operator only supports legacy coordinate pairs and 2d |
||
634 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
635 | * |
||
636 | * @see Expr::geoWithinPolygon() |
||
637 | * @see http://docs.mongodb.org/manual/reference/operator/polygon/ |
||
638 | * |
||
639 | * @param array $point1 First point of the polygon |
||
640 | * @param array $point2 Second point of the polygon |
||
641 | * @param array $point3 Third point of the polygon |
||
642 | * @param array ...$points Additional points of the polygon |
||
643 | */ |
||
644 | 1 | public function geoWithinPolygon($point1, $point2, $point3, ...$points) : self |
|
650 | |||
651 | /** |
||
652 | * Return the expression's "new object". |
||
653 | * |
||
654 | * @see Expr::getNewObj() |
||
655 | */ |
||
656 | 13 | public function getNewObj() : array |
|
660 | |||
661 | /** |
||
662 | * Gets the Query executable. |
||
663 | */ |
||
664 | 155 | public function getQuery(array $options = []) : Query |
|
719 | |||
720 | /** |
||
721 | * Return the expression's query criteria. |
||
722 | * |
||
723 | * @see Expr::getQuery() |
||
724 | */ |
||
725 | 32 | public function getQueryArray() : array |
|
729 | |||
730 | /** |
||
731 | * Get the type of this query. |
||
732 | */ |
||
733 | public function getType() : int |
||
737 | |||
738 | /** |
||
739 | * Specify $gt criteria for the current field. |
||
740 | * |
||
741 | * @see Expr::gt() |
||
742 | * @see http://docs.mongodb.org/manual/reference/operator/gt/ |
||
743 | * |
||
744 | * @param mixed $value |
||
745 | */ |
||
746 | 2 | public function gt($value) : self |
|
752 | |||
753 | /** |
||
754 | * Specify $gte criteria for the current field. |
||
755 | * |
||
756 | * @see Expr::gte() |
||
757 | * @see http://docs.mongodb.org/manual/reference/operator/gte/ |
||
758 | * |
||
759 | * @param mixed $value |
||
760 | */ |
||
761 | 2 | public function gte($value) : self |
|
767 | |||
768 | /** |
||
769 | * Set the index hint for the query. |
||
770 | * |
||
771 | * @param array|string $index |
||
772 | */ |
||
773 | public function hint($index) : self |
||
779 | |||
780 | 17 | public function hydrate(bool $bool = true) : self |
|
786 | |||
787 | /** |
||
788 | * Set the immortal cursor flag. |
||
789 | */ |
||
790 | public function immortal(bool $bool = true) : self |
||
796 | |||
797 | /** |
||
798 | * Specify $in criteria for the current field. |
||
799 | * |
||
800 | * @see Expr::in() |
||
801 | * @see http://docs.mongodb.org/manual/reference/operator/in/ |
||
802 | */ |
||
803 | 24 | public function in(array $values) : self |
|
809 | |||
810 | /** |
||
811 | * Increment the current field. |
||
812 | * |
||
813 | * If the field does not exist, it will be set to this value. |
||
814 | * |
||
815 | * @see Expr::inc() |
||
816 | * @see http://docs.mongodb.org/manual/reference/operator/inc/ |
||
817 | * |
||
818 | * @param float|int $value |
||
819 | */ |
||
820 | 6 | public function inc($value) : self |
|
826 | |||
827 | 6 | public function includesReferenceTo(object $document) : self |
|
833 | |||
834 | 1 | public function insert(?string $documentName = null) : self |
|
841 | |||
842 | /** |
||
843 | * Set the $language option for $text criteria. |
||
844 | * |
||
845 | * This method must be called after text(). |
||
846 | * |
||
847 | * @see Expr::language() |
||
848 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
849 | */ |
||
850 | 1 | public function language(string $language) : self |
|
856 | |||
857 | /** |
||
858 | * Set the limit for the query. |
||
859 | * |
||
860 | * This is only relevant for find queries and count commands. |
||
861 | * |
||
862 | * @see Query::prepareCursor() |
||
863 | */ |
||
864 | 2 | public function limit(int $limit) : self |
|
870 | |||
871 | /** |
||
872 | * Specify $lt criteria for the current field. |
||
873 | * |
||
874 | * @see Expr::lte() |
||
875 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
876 | * |
||
877 | * @param mixed $value |
||
878 | */ |
||
879 | public function lt($value) : self |
||
885 | |||
886 | /** |
||
887 | * Specify $lte criteria for the current field. |
||
888 | * |
||
889 | * @see Expr::lte() |
||
890 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
891 | * |
||
892 | * @param mixed $value |
||
893 | */ |
||
894 | public function lte($value) : self |
||
900 | |||
901 | /** |
||
902 | * Updates the value of the field to a specified value if the specified value is greater than the current value of the field. |
||
903 | * |
||
904 | * @see Expr::max() |
||
905 | * @see http://docs.mongodb.org/manual/reference/operator/update/max/ |
||
906 | * |
||
907 | * @param mixed $value |
||
908 | */ |
||
909 | 1 | public function max($value) : self |
|
915 | |||
916 | /** |
||
917 | * Specifies a cumulative time limit in milliseconds for processing operations on a cursor. |
||
918 | */ |
||
919 | public function maxTimeMS(int $ms) : self |
||
925 | |||
926 | /** |
||
927 | * Updates the value of the field to a specified value if the specified value is less than the current value of the field. |
||
928 | * |
||
929 | * @see Expr::min() |
||
930 | * @see http://docs.mongodb.org/manual/reference/operator/update/min/ |
||
931 | * |
||
932 | * @param mixed $value |
||
933 | */ |
||
934 | 1 | public function min($value) : self |
|
940 | |||
941 | /** |
||
942 | * Specify $mod criteria for the current field. |
||
943 | * |
||
944 | * @see Expr::mod() |
||
945 | * @see http://docs.mongodb.org/manual/reference/operator/mod/ |
||
946 | * |
||
947 | * @param float|int $divisor |
||
948 | * @param float|int $remainder |
||
949 | */ |
||
950 | 1 | public function mod($divisor, $remainder = 0) : self |
|
956 | |||
957 | /** |
||
958 | * Multiply the current field. |
||
959 | * |
||
960 | * If the field does not exist, it will be set to 0. |
||
961 | * |
||
962 | * @see Expr::mul() |
||
963 | * @see http://docs.mongodb.org/manual/reference/operator/mul/ |
||
964 | * |
||
965 | * @param float|int $value |
||
966 | */ |
||
967 | 1 | public function mul($value) : self |
|
973 | |||
974 | /** |
||
975 | * Add $near criteria to the query. |
||
976 | * |
||
977 | * A GeoJSON point may be provided as the first and only argument for |
||
978 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
979 | * an array corresponding to the point's JSON representation. |
||
980 | * |
||
981 | * @see Expr::near() |
||
982 | * @see http://docs.mongodb.org/manual/reference/operator/near/ |
||
983 | * |
||
984 | * @param float|array|Point $x |
||
985 | * @param float $y |
||
986 | */ |
||
987 | 1 | public function near($x, $y = null) : self |
|
993 | |||
994 | /** |
||
995 | * Add $nearSphere criteria to the query. |
||
996 | * |
||
997 | * A GeoJSON point may be provided as the first and only argument for |
||
998 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
999 | * an array corresponding to the point's JSON representation. |
||
1000 | * |
||
1001 | * @see Expr::nearSphere() |
||
1002 | * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/ |
||
1003 | * |
||
1004 | * @param float|array|Point $x |
||
1005 | * @param float $y |
||
1006 | */ |
||
1007 | 1 | public function nearSphere($x, $y = null) : self |
|
1013 | |||
1014 | /** |
||
1015 | * Negates an expression for the current field. |
||
1016 | * |
||
1017 | * You can create a new expression using the {@link Builder::expr()} method. |
||
1018 | * |
||
1019 | * @see Expr::not() |
||
1020 | * @see http://docs.mongodb.org/manual/reference/operator/not/ |
||
1021 | * |
||
1022 | * @param array|Expr $expression |
||
1023 | */ |
||
1024 | 3 | public function not($expression) : self |
|
1030 | |||
1031 | /** |
||
1032 | * Specify $ne criteria for the current field. |
||
1033 | * |
||
1034 | * @see Expr::notEqual() |
||
1035 | * @see http://docs.mongodb.org/manual/reference/operator/ne/ |
||
1036 | * |
||
1037 | * @param mixed $value |
||
1038 | */ |
||
1039 | 4 | public function notEqual($value) : self |
|
1045 | |||
1046 | /** |
||
1047 | * Specify $nin criteria for the current field. |
||
1048 | * |
||
1049 | * @see Expr::notIn() |
||
1050 | * @see http://docs.mongodb.org/manual/reference/operator/nin/ |
||
1051 | * |
||
1052 | * @param array $values |
||
1053 | */ |
||
1054 | 4 | public function notIn(array $values) : self |
|
1060 | |||
1061 | /** |
||
1062 | * Remove the first element from the current array field. |
||
1063 | * |
||
1064 | * @see Expr::popFirst() |
||
1065 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
1066 | */ |
||
1067 | 3 | public function popFirst() : self |
|
1073 | |||
1074 | /** |
||
1075 | * Remove the last element from the current array field. |
||
1076 | * |
||
1077 | * @see Expr::popLast() |
||
1078 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
1079 | */ |
||
1080 | 2 | public function popLast() : self |
|
1086 | |||
1087 | /** |
||
1088 | * Use a primer to eagerly load all references in the current field. |
||
1089 | * |
||
1090 | * If $primer is true or a callable is provided, referenced documents for |
||
1091 | * this field will loaded into UnitOfWork immediately after the query is |
||
1092 | * executed. This will avoid multiple queries due to lazy initialization of |
||
1093 | * Proxy objects. |
||
1094 | * |
||
1095 | * If $primer is false, no priming will take place. That is also the default |
||
1096 | * behavior. |
||
1097 | * |
||
1098 | * If a custom callable is used, its signature should conform to the default |
||
1099 | * Closure defined in {@link ReferencePrimer::__construct()}. |
||
1100 | * |
||
1101 | * @param bool|callable $primer |
||
1102 | * |
||
1103 | * @throws InvalidArgumentException If $primer is not boolean or callable. |
||
1104 | */ |
||
1105 | 22 | public function prime($primer = true) : self |
|
1121 | |||
1122 | /** |
||
1123 | * Remove all elements matching the given value or expression from the |
||
1124 | * current array field. |
||
1125 | * |
||
1126 | * @see Expr::pull() |
||
1127 | * @see http://docs.mongodb.org/manual/reference/operator/pull/ |
||
1128 | * |
||
1129 | * @param mixed|Expr $valueOrExpression |
||
1130 | */ |
||
1131 | 1 | public function pull($valueOrExpression) : self |
|
1137 | |||
1138 | /** |
||
1139 | * Remove all elements matching any of the given values from the current |
||
1140 | * array field. |
||
1141 | * |
||
1142 | * @see Expr::pullAll() |
||
1143 | * @see http://docs.mongodb.org/manual/reference/operator/pullAll/ |
||
1144 | */ |
||
1145 | 1 | public function pullAll(array $values) : self |
|
1151 | |||
1152 | /** |
||
1153 | * Append one or more values to the current array field. |
||
1154 | * |
||
1155 | * If the field does not exist, it will be set to an array containing the |
||
1156 | * value(s) in the argument. If the field is not an array, the query |
||
1157 | * will yield an error. |
||
1158 | * |
||
1159 | * Multiple values may be specified by providing an Expr object and using |
||
1160 | * {@link Expr::each()}. {@link Expr::slice()} and {@link Expr::sort()} may |
||
1161 | * also be used to limit and order array elements, respectively. |
||
1162 | * |
||
1163 | * @see Expr::push() |
||
1164 | * @see http://docs.mongodb.org/manual/reference/operator/push/ |
||
1165 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
1166 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
1167 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
1168 | * |
||
1169 | * @param mixed|Expr $valueOrExpression |
||
1170 | */ |
||
1171 | 6 | public function push($valueOrExpression) : self |
|
1177 | |||
1178 | /** |
||
1179 | * Specify $gte and $lt criteria for the current field. |
||
1180 | * |
||
1181 | * This method is shorthand for specifying $gte criteria on the lower bound |
||
1182 | * and $lt criteria on the upper bound. The upper bound is not inclusive. |
||
1183 | * |
||
1184 | * @see Expr::range() |
||
1185 | * |
||
1186 | * @param mixed $start |
||
1187 | * @param mixed $end |
||
1188 | */ |
||
1189 | 3 | public function range($start, $end) : self |
|
1195 | |||
1196 | 2 | public function readOnly(bool $bool = true) : self |
|
1202 | |||
1203 | 10 | public function references(object $document) : self |
|
1209 | |||
1210 | 5 | public function refresh(bool $bool = true) : self |
|
1216 | |||
1217 | 1 | public function remove(?string $documentName = null) : self |
|
1224 | |||
1225 | /** |
||
1226 | * Rename the current field. |
||
1227 | * |
||
1228 | * @see Expr::rename() |
||
1229 | * @see http://docs.mongodb.org/manual/reference/operator/rename/ |
||
1230 | */ |
||
1231 | public function rename(string $name) : self |
||
1237 | |||
1238 | 4 | public function returnNew(bool $bool = true) : self |
|
1245 | |||
1246 | /** |
||
1247 | * Set one or more fields to be included in the query projection. |
||
1248 | * |
||
1249 | * @param array|string $fieldName,... |
||
1250 | */ |
||
1251 | 19 | public function select($fieldName = null) : self |
|
1265 | |||
1266 | /** |
||
1267 | * Select only matching embedded documents in an array field for the query |
||
1268 | * projection. |
||
1269 | * |
||
1270 | * @see http://docs.mongodb.org/manual/reference/projection/elemMatch/ |
||
1271 | * |
||
1272 | * @param array|Expr $expression |
||
1273 | */ |
||
1274 | 2 | public function selectElemMatch(string $fieldName, $expression) : self |
|
1283 | |||
1284 | /** |
||
1285 | * Select a metadata field for the query projection. |
||
1286 | * |
||
1287 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/ |
||
1288 | */ |
||
1289 | 3 | public function selectMeta(string $fieldName, string $metaDataKeyword) : self |
|
1295 | |||
1296 | /** |
||
1297 | * Select a slice of an array field for the query projection. |
||
1298 | * |
||
1299 | * The $countOrSkip parameter has two very different meanings, depending on |
||
1300 | * whether or not $limit is provided. See the MongoDB documentation for more |
||
1301 | * information. |
||
1302 | * |
||
1303 | * @see http://docs.mongodb.org/manual/reference/projection/slice/ |
||
1304 | */ |
||
1305 | 3 | public function selectSlice(string $fieldName, int $countOrSkip, ?int $limit = null) : self |
|
1315 | |||
1316 | /** |
||
1317 | * Set the current field to a value. |
||
1318 | * |
||
1319 | * This is only relevant for insert, update, or findAndUpdate queries. For |
||
1320 | * update and findAndUpdate queries, the $atomic parameter will determine |
||
1321 | * whether or not a $set operator is used. |
||
1322 | * |
||
1323 | * @see Expr::set() |
||
1324 | * @see http://docs.mongodb.org/manual/reference/operator/set/ |
||
1325 | * |
||
1326 | * @param mixed $value |
||
1327 | */ |
||
1328 | 16 | public function set($value, bool $atomic = true) : self |
|
1334 | |||
1335 | /** |
||
1336 | * Set the expression's "new object". |
||
1337 | * |
||
1338 | * @see Expr::setNewObj() |
||
1339 | */ |
||
1340 | 1 | public function setNewObj(array $newObj) : self |
|
1346 | |||
1347 | /** |
||
1348 | * Set the current field to the value if the document is inserted in an |
||
1349 | * upsert operation. |
||
1350 | * |
||
1351 | * If an update operation with upsert: true results in an insert of a |
||
1352 | * document, then $setOnInsert assigns the specified values to the fields in |
||
1353 | * the document. If the update operation does not result in an insert, |
||
1354 | * $setOnInsert does nothing. |
||
1355 | * |
||
1356 | * @see Expr::setOnInsert() |
||
1357 | * @see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ |
||
1358 | * |
||
1359 | * @param mixed $value |
||
1360 | */ |
||
1361 | 2 | public function setOnInsert($value) : self |
|
1367 | |||
1368 | /** |
||
1369 | * Set the read preference for the query. |
||
1370 | * |
||
1371 | * This is only relevant for read-only queries and commands. |
||
1372 | * |
||
1373 | * @see http://docs.mongodb.org/manual/core/read-preference/ |
||
1374 | */ |
||
1375 | 6 | public function setReadPreference(ReadPreference $readPreference) : self |
|
1381 | |||
1382 | /** |
||
1383 | * Set the expression's query criteria. |
||
1384 | * |
||
1385 | * @see Expr::setQuery() |
||
1386 | */ |
||
1387 | 18 | public function setQueryArray(array $query) : self |
|
1393 | |||
1394 | /** |
||
1395 | * Specify $size criteria for the current field. |
||
1396 | * |
||
1397 | * @see Expr::size() |
||
1398 | * @see http://docs.mongodb.org/manual/reference/operator/size/ |
||
1399 | */ |
||
1400 | 1 | public function size(int $size) : self |
|
1406 | |||
1407 | /** |
||
1408 | * Set the skip for the query cursor. |
||
1409 | * |
||
1410 | * This is only relevant for find queries, or mapReduce queries that store |
||
1411 | * results in an output collection and return a cursor. |
||
1412 | * |
||
1413 | * @see Query::prepareCursor() |
||
1414 | */ |
||
1415 | public function skip(int $skip) : self |
||
1421 | |||
1422 | /** |
||
1423 | * Set the snapshot cursor flag. |
||
1424 | */ |
||
1425 | public function snapshot(bool $bool = true) : self |
||
1431 | |||
1432 | /** |
||
1433 | * Set one or more field/order pairs on which to sort the query. |
||
1434 | * |
||
1435 | * If sorting by multiple fields, the first argument should be an array of |
||
1436 | * field name (key) and order (value) pairs. |
||
1437 | * |
||
1438 | * @param array|string $fieldName Field name or array of field/order pairs |
||
1439 | * @param int|string $order Field order (if one field is specified) |
||
1440 | */ |
||
1441 | 28 | public function sort($fieldName, $order = 1) : self |
|
1458 | |||
1459 | /** |
||
1460 | * Specify a projected metadata field on which to sort the query. |
||
1461 | * |
||
1462 | * Sort order is not configurable for metadata fields. Sorting by a metadata |
||
1463 | * field requires the same field and $meta expression to exist in the |
||
1464 | * projection document. This method will call {@link Builder::selectMeta()} |
||
1465 | * if the field is not already set in the projection. |
||
1466 | * |
||
1467 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/#sort |
||
1468 | */ |
||
1469 | 3 | public function sortMeta(string $fieldName, string $metaDataKeyword) : self |
|
1483 | |||
1484 | /** |
||
1485 | * Specify $text criteria for the current field. |
||
1486 | * |
||
1487 | * The $language option may be set with {@link Builder::language()}. |
||
1488 | * |
||
1489 | * @see Expr::text() |
||
1490 | * @see http://docs.mongodb.org/master/reference/operator/query/text/ |
||
1491 | */ |
||
1492 | 1 | public function text(string $search) : self |
|
1498 | |||
1499 | /** |
||
1500 | * Specify $type criteria for the current field. |
||
1501 | * |
||
1502 | * @see Expr::type() |
||
1503 | * @see http://docs.mongodb.org/manual/reference/operator/type/ |
||
1504 | * |
||
1505 | * @param int|string $type |
||
1506 | */ |
||
1507 | 2 | public function type($type) : self |
|
1513 | |||
1514 | /** |
||
1515 | * Unset the current field. |
||
1516 | * |
||
1517 | * The field will be removed from the document (not set to null). |
||
1518 | * |
||
1519 | * @see Expr::unsetField() |
||
1520 | * @see http://docs.mongodb.org/manual/reference/operator/unset/ |
||
1521 | */ |
||
1522 | 4 | public function unsetField() : self |
|
1528 | |||
1529 | 23 | public function updateOne(?string $documentName = null) : self |
|
1537 | |||
1538 | 4 | public function updateMany(?string $documentName = null) : self |
|
1546 | |||
1547 | /** |
||
1548 | * Set the "upsert" option for an update or findAndUpdate query. |
||
1549 | */ |
||
1550 | 7 | public function upsert(bool $bool = true) : self |
|
1556 | |||
1557 | /** |
||
1558 | * Specify a JavaScript expression to use for matching documents. |
||
1559 | * |
||
1560 | * @see Expr::where() |
||
1561 | * @see http://docs.mongodb.org/manual/reference/operator/where/ |
||
1562 | * |
||
1563 | * @param string|Javascript $javascript |
||
1564 | */ |
||
1565 | 3 | public function where($javascript) : self |
|
1571 | |||
1572 | /** |
||
1573 | * Get Discriminator Values |
||
1574 | * |
||
1575 | * @param string[] $classNames |
||
1576 | * |
||
1577 | * @throws InvalidArgumentException If the number of found collections > 1. |
||
1578 | */ |
||
1579 | 2 | private function getDiscriminatorValues($classNames) : array |
|
1595 | |||
1596 | /** |
||
1597 | * @param string[]|string|null $documentName an array of document names or just one. |
||
1598 | */ |
||
1599 | 281 | private function setDocumentName($documentName) |
|
1627 | } |
||
1628 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.