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 |
||
| 30 | class Builder |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * The DocumentManager instance for this query |
||
| 34 | * |
||
| 35 | * @var DocumentManager |
||
| 36 | */ |
||
| 37 | private $dm; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The ClassMetadata instance. |
||
| 41 | * |
||
| 42 | * @var ClassMetadata |
||
| 43 | */ |
||
| 44 | private $class; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * The current field we are operating on. |
||
| 48 | * |
||
| 49 | * @todo Change this to private once ODM requires doctrine/mongodb 1.1+ |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | protected $currentField; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Whether or not to hydrate the data to documents. |
||
| 56 | * |
||
| 57 | * @var bool |
||
| 58 | */ |
||
| 59 | private $hydrate = true; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Whether or not to refresh the data for documents that are already in the identity map. |
||
| 63 | * |
||
| 64 | * @var bool |
||
| 65 | */ |
||
| 66 | private $refresh = false; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Array of primer Closure instances. |
||
| 70 | * |
||
| 71 | * @var array |
||
| 72 | */ |
||
| 73 | private $primers = []; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Whether or not to register documents in UnitOfWork. |
||
| 77 | * |
||
| 78 | * @var bool |
||
| 79 | */ |
||
| 80 | private $readOnly; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * The Collection instance. |
||
| 84 | * |
||
| 85 | * @var Collection |
||
| 86 | */ |
||
| 87 | private $collection; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Array containing the query data. |
||
| 91 | * |
||
| 92 | * @var array |
||
| 93 | */ |
||
| 94 | private $query = ['type' => Query::TYPE_FIND]; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * The Expr instance used for building this query. |
||
| 98 | * |
||
| 99 | * This object includes the query criteria and the "new object" used for |
||
| 100 | * insert and update queries. |
||
| 101 | * |
||
| 102 | * @var Expr $expr |
||
| 103 | */ |
||
| 104 | private $expr; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Construct a Builder |
||
| 108 | * |
||
| 109 | * @param string[]|string|null $documentName (optional) an array of document names, the document name, or none |
||
| 110 | */ |
||
| 111 | 285 | public function __construct(DocumentManager $dm, $documentName = null) |
|
| 121 | |||
| 122 | 1 | public function __clone() |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Add one or more $and clauses to the current query. |
||
| 129 | * |
||
| 130 | * You can create a new expression using the {@link Builder::expr()} method. |
||
| 131 | * |
||
| 132 | * @see Expr::addAnd() |
||
| 133 | * @see http://docs.mongodb.org/manual/reference/operator/and/ |
||
| 134 | * @param array|Expr $expression |
||
| 135 | * @param array|Expr ...$expressions |
||
| 136 | * @return $this |
||
| 137 | */ |
||
| 138 | 4 | public function addAnd($expression, ...$expressions) |
|
| 143 | |||
| 144 | /** |
||
| 145 | * Add one or more $nor clauses to the current query. |
||
| 146 | * |
||
| 147 | * You can create a new expression using the {@link Builder::expr()} method. |
||
| 148 | * |
||
| 149 | * @see Expr::addNor() |
||
| 150 | * @see http://docs.mongodb.org/manual/reference/operator/nor/ |
||
| 151 | * @param array|Expr $expression |
||
| 152 | * @param array|Expr ...$expressions |
||
| 153 | * @return $this |
||
| 154 | */ |
||
| 155 | 3 | public function addNor($expression, ...$expressions) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * Add one or more $or clauses to the current query. |
||
| 163 | * |
||
| 164 | * You can create a new expression using the {@link Builder::expr()} method. |
||
| 165 | * |
||
| 166 | * @see Expr::addOr() |
||
| 167 | * @see http://docs.mongodb.org/manual/reference/operator/or/ |
||
| 168 | * @param array|Expr $expression |
||
| 169 | * @param array|Expr ...$expressions |
||
| 170 | * @return $this |
||
| 171 | */ |
||
| 172 | 6 | public function addOr($expression, ...$expressions) |
|
| 177 | |||
| 178 | /** |
||
| 179 | * Append one or more values to the current array field only if they do not |
||
| 180 | * already exist in the array. |
||
| 181 | * |
||
| 182 | * If the field does not exist, it will be set to an array containing the |
||
| 183 | * unique value(s) in the argument. If the field is not an array, the query |
||
| 184 | * will yield an error. |
||
| 185 | * |
||
| 186 | * Multiple values may be specified by provided an Expr object and using |
||
| 187 | * {@link Expr::each()}. |
||
| 188 | * |
||
| 189 | * @see Expr::addToSet() |
||
| 190 | * @see http://docs.mongodb.org/manual/reference/operator/addToSet/ |
||
| 191 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 192 | * @param mixed|Expr $valueOrExpression |
||
| 193 | * @return $this |
||
| 194 | */ |
||
| 195 | 5 | public function addToSet($valueOrExpression) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Specify $all criteria for the current field. |
||
| 203 | * |
||
| 204 | * @see Expr::all() |
||
| 205 | * @see http://docs.mongodb.org/manual/reference/operator/all/ |
||
| 206 | * @param array $values |
||
| 207 | * @return $this |
||
| 208 | */ |
||
| 209 | 3 | public function all(array $values) |
|
| 214 | |||
| 215 | /** |
||
| 216 | * Apply a bitwise and operation on the current field. |
||
| 217 | * |
||
| 218 | * @see Expr::bitAnd() |
||
| 219 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 220 | * @param int $value |
||
| 221 | * @return $this |
||
| 222 | */ |
||
| 223 | 1 | public function bitAnd($value) |
|
| 228 | |||
| 229 | /** |
||
| 230 | * Apply a bitwise or operation on the current field. |
||
| 231 | * |
||
| 232 | * @see Expr::bitOr() |
||
| 233 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 234 | * @param int $value |
||
| 235 | * @return $this |
||
| 236 | */ |
||
| 237 | 1 | public function bitOr($value) |
|
| 242 | |||
| 243 | /** |
||
| 244 | * Matches documents where all of the bit positions given by the query are |
||
| 245 | * clear. |
||
| 246 | * |
||
| 247 | * @see Expr::bitsAllClear() |
||
| 248 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/ |
||
| 249 | * @param int|array|Binary $value |
||
| 250 | * @return $this |
||
| 251 | */ |
||
| 252 | 1 | public function bitsAllClear($value) |
|
| 257 | |||
| 258 | /** |
||
| 259 | * Matches documents where all of the bit positions given by the query are |
||
| 260 | * set. |
||
| 261 | * |
||
| 262 | * @see Expr::bitsAllSet() |
||
| 263 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllSet/ |
||
| 264 | * @param int|array|Binary $value |
||
| 265 | * @return $this |
||
| 266 | */ |
||
| 267 | 1 | public function bitsAllSet($value) |
|
| 272 | |||
| 273 | /** |
||
| 274 | * Matches documents where any of the bit positions given by the query are |
||
| 275 | * clear. |
||
| 276 | * |
||
| 277 | * @see Expr::bitsAnyClear() |
||
| 278 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnyClear/ |
||
| 279 | * @param int|array|Binary $value |
||
| 280 | * @return $this |
||
| 281 | */ |
||
| 282 | 1 | public function bitsAnyClear($value) |
|
| 287 | |||
| 288 | /** |
||
| 289 | * Matches documents where any of the bit positions given by the query are |
||
| 290 | * set. |
||
| 291 | * |
||
| 292 | * @see Expr::bitsAnySet() |
||
| 293 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnySet/ |
||
| 294 | * @param int|array|Binary $value |
||
| 295 | * @return $this |
||
| 296 | */ |
||
| 297 | 1 | public function bitsAnySet($value) |
|
| 302 | |||
| 303 | /** |
||
| 304 | * Apply a bitwise xor operation on the current field. |
||
| 305 | * |
||
| 306 | * @see Expr::bitXor() |
||
| 307 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 308 | * @param int $value |
||
| 309 | * @return $this |
||
| 310 | */ |
||
| 311 | 1 | public function bitXor($value) |
|
| 316 | |||
| 317 | /** |
||
| 318 | * A boolean flag to enable or disable case sensitive search for $text |
||
| 319 | * criteria. |
||
| 320 | * |
||
| 321 | * This method must be called after text(). |
||
| 322 | * |
||
| 323 | * @see Expr::caseSensitive() |
||
| 324 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 325 | * @param bool $caseSensitive |
||
| 326 | * @return $this |
||
| 327 | * @throws \BadMethodCallException If the query does not already have $text criteria. |
||
| 328 | * |
||
| 329 | */ |
||
| 330 | 1 | public function caseSensitive($caseSensitive) |
|
| 335 | |||
| 336 | /** |
||
| 337 | * Associates a comment to any expression taking a query predicate. |
||
| 338 | * |
||
| 339 | * @see Expr::comment() |
||
| 340 | * @see http://docs.mongodb.org/manual/reference/operator/query/comment/ |
||
| 341 | * @param string $comment |
||
| 342 | * @return $this |
||
| 343 | */ |
||
| 344 | 1 | public function comment($comment) |
|
| 349 | |||
| 350 | /** |
||
| 351 | * Change the query type to count. |
||
| 352 | * |
||
| 353 | * @return $this |
||
| 354 | */ |
||
| 355 | public function count() |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Sets the value of the current field to the current date, either as a date or a timestamp. |
||
| 363 | * |
||
| 364 | * @see Expr::currentDate() |
||
| 365 | * @see http://docs.mongodb.org/manual/reference/operator/currentDate/ |
||
| 366 | * @param string $type |
||
| 367 | * @return $this |
||
| 368 | */ |
||
| 369 | 3 | public function currentDate($type = 'date') |
|
| 374 | |||
| 375 | /** |
||
| 376 | * Return an array of information about the Builder state for debugging. |
||
| 377 | * |
||
| 378 | * The $name parameter may be used to return a specific key from the |
||
| 379 | * internal $query array property. If omitted, the entire array will be |
||
| 380 | * returned. |
||
| 381 | * |
||
| 382 | * @param string $name |
||
| 383 | * @return mixed |
||
| 384 | */ |
||
| 385 | 28 | public function debug($name = null) |
|
| 389 | |||
| 390 | /** |
||
| 391 | * A boolean flag to enable or disable diacritic sensitive search for $text |
||
| 392 | * criteria. |
||
| 393 | * |
||
| 394 | * This method must be called after text(). |
||
| 395 | * |
||
| 396 | * @see Builder::diacriticSensitive() |
||
| 397 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 398 | * @param bool $diacriticSensitive |
||
| 399 | * @return $this |
||
| 400 | * @throws \BadMethodCallException If the query does not already have $text criteria. |
||
| 401 | * |
||
| 402 | */ |
||
| 403 | 1 | public function diacriticSensitive($diacriticSensitive) |
|
| 408 | |||
| 409 | /** |
||
| 410 | * Change the query type to a distinct command. |
||
| 411 | * |
||
| 412 | * @see http://docs.mongodb.org/manual/reference/command/distinct/ |
||
| 413 | * @param string $field |
||
| 414 | * @return $this |
||
| 415 | */ |
||
| 416 | 2 | public function distinct($field) |
|
| 422 | |||
| 423 | /** |
||
| 424 | * Set whether the query should return its result as an EagerCursor. |
||
| 425 | * |
||
| 426 | * @param bool $bool |
||
| 427 | * @return $this |
||
| 428 | */ |
||
| 429 | 5 | public function eagerCursor($bool = true) |
|
| 438 | |||
| 439 | /** |
||
| 440 | * Specify $elemMatch criteria for the current field. |
||
| 441 | * |
||
| 442 | * You can create a new expression using the {@link Builder::expr()} method. |
||
| 443 | * |
||
| 444 | * @see Expr::elemMatch() |
||
| 445 | * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/ |
||
| 446 | * @param array|Expr $expression |
||
| 447 | * @return $this |
||
| 448 | */ |
||
| 449 | 6 | public function elemMatch($expression) |
|
| 454 | |||
| 455 | /** |
||
| 456 | * Specify an equality match for the current field. |
||
| 457 | * |
||
| 458 | * @see Expr::equals() |
||
| 459 | * @param mixed $value |
||
| 460 | * @return $this |
||
| 461 | */ |
||
| 462 | 75 | public function equals($value) |
|
| 467 | |||
| 468 | /** |
||
| 469 | * Set one or more fields to be excluded from the query projection. |
||
| 470 | * |
||
| 471 | * If fields have been selected for inclusion, only the "_id" field may be |
||
| 472 | * excluded. |
||
| 473 | * |
||
| 474 | * @param array|string $fieldName,... |
||
| 475 | * @return $this |
||
| 476 | */ |
||
| 477 | 6 | View Code Duplication | public function exclude($fieldName = null) |
| 491 | |||
| 492 | /** |
||
| 493 | * Specify $exists criteria for the current field. |
||
| 494 | * |
||
| 495 | * @see Expr::exists() |
||
| 496 | * @see http://docs.mongodb.org/manual/reference/operator/exists/ |
||
| 497 | * @param bool $bool |
||
| 498 | * @return $this |
||
| 499 | */ |
||
| 500 | 5 | public function exists($bool) |
|
| 505 | |||
| 506 | /** |
||
| 507 | * Create a new Expr instance that can be used as an expression with the Builder |
||
| 508 | * |
||
| 509 | * @return Expr $expr |
||
| 510 | */ |
||
| 511 | 26 | public function expr() |
|
| 518 | |||
| 519 | /** |
||
| 520 | * Set the current field to operate on. |
||
| 521 | * |
||
| 522 | * @param string $field |
||
| 523 | * @return $this |
||
| 524 | */ |
||
| 525 | 144 | public function field($field) |
|
| 532 | |||
| 533 | /** |
||
| 534 | * Set the "finalize" option for a mapReduce or group command. |
||
| 535 | * |
||
| 536 | * @param string|Javascript $finalize |
||
| 537 | * @return $this |
||
| 538 | * @throws \BadMethodCallException If the query is not a mapReduce or group command. |
||
| 539 | */ |
||
| 540 | 2 | View Code Duplication | public function finalize($finalize) |
| 557 | |||
| 558 | /** |
||
| 559 | * Change the query type to find and optionally set and change the class being queried. |
||
| 560 | * |
||
| 561 | * @param string $documentName |
||
| 562 | * @return $this |
||
| 563 | */ |
||
| 564 | 12 | public function find($documentName = null) |
|
| 571 | |||
| 572 | /** |
||
| 573 | * @param string $documentName |
||
| 574 | * @return $this |
||
| 575 | */ |
||
| 576 | 1 | public function findAndRemove($documentName = null) |
|
| 583 | |||
| 584 | /** |
||
| 585 | * @param string $documentName |
||
| 586 | * @return $this |
||
| 587 | */ |
||
| 588 | 13 | public function findAndUpdate($documentName = null) |
|
| 595 | |||
| 596 | /** |
||
| 597 | * Add $geoIntersects criteria with a GeoJSON geometry to the query. |
||
| 598 | * |
||
| 599 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
| 600 | * geometry's JSON representation. |
||
| 601 | * |
||
| 602 | * @see Expr::geoIntersects() |
||
| 603 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
| 604 | * @param array|Geometry $geometry |
||
| 605 | * @return $this |
||
| 606 | */ |
||
| 607 | 1 | public function geoIntersects($geometry) |
|
| 612 | |||
| 613 | /** |
||
| 614 | * Add $geoWithin criteria with a GeoJSON geometry to the query. |
||
| 615 | * |
||
| 616 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
| 617 | * geometry's JSON representation. |
||
| 618 | * |
||
| 619 | * @see Expr::geoWithin() |
||
| 620 | * @see http://docs.mongodb.org/manual/reference/operator/geoWithin/ |
||
| 621 | * @param array|Geometry $geometry |
||
| 622 | * @return $this |
||
| 623 | */ |
||
| 624 | 1 | public function geoWithin($geometry) |
|
| 629 | |||
| 630 | /** |
||
| 631 | * Add $geoWithin criteria with a $box shape to the query. |
||
| 632 | * |
||
| 633 | * A rectangular polygon will be constructed from a pair of coordinates |
||
| 634 | * corresponding to the bottom left and top right corners. |
||
| 635 | * |
||
| 636 | * Note: the $box operator only supports legacy coordinate pairs and 2d |
||
| 637 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 638 | * |
||
| 639 | * @see Expr::geoWithinBox() |
||
| 640 | * @see http://docs.mongodb.org/manual/reference/operator/box/ |
||
| 641 | * @param float $x1 |
||
| 642 | * @param float $y1 |
||
| 643 | * @param float $x2 |
||
| 644 | * @param float $y2 |
||
| 645 | * @return $this |
||
| 646 | */ |
||
| 647 | 1 | public function geoWithinBox($x1, $y1, $x2, $y2) |
|
| 652 | |||
| 653 | /** |
||
| 654 | * Add $geoWithin criteria with a $center shape to the query. |
||
| 655 | * |
||
| 656 | * Note: the $center operator only supports legacy coordinate pairs and 2d |
||
| 657 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 658 | * |
||
| 659 | * @see Expr::geoWithinCenter() |
||
| 660 | * @see http://docs.mongodb.org/manual/reference/operator/center/ |
||
| 661 | * @param float $x |
||
| 662 | * @param float $y |
||
| 663 | * @param float $radius |
||
| 664 | * @return $this |
||
| 665 | */ |
||
| 666 | 1 | public function geoWithinCenter($x, $y, $radius) |
|
| 671 | |||
| 672 | /** |
||
| 673 | * Add $geoWithin criteria with a $centerSphere shape to the query. |
||
| 674 | * |
||
| 675 | * Note: the $centerSphere operator supports both 2d and 2dsphere indexes. |
||
| 676 | * |
||
| 677 | * @see Expr::geoWithinCenterSphere() |
||
| 678 | * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/ |
||
| 679 | * @param float $x |
||
| 680 | * @param float $y |
||
| 681 | * @param float $radius |
||
| 682 | * @return $this |
||
| 683 | */ |
||
| 684 | 1 | public function geoWithinCenterSphere($x, $y, $radius) |
|
| 689 | |||
| 690 | /** |
||
| 691 | * Add $geoWithin criteria with a $polygon shape to the query. |
||
| 692 | * |
||
| 693 | * Point coordinates are in x, y order (easting, northing for projected |
||
| 694 | * coordinates, longitude, latitude for geographic coordinates). |
||
| 695 | * |
||
| 696 | * The last point coordinate is implicitly connected with the first. |
||
| 697 | * |
||
| 698 | * Note: the $polygon operator only supports legacy coordinate pairs and 2d |
||
| 699 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 700 | * |
||
| 701 | * @see Expr::geoWithinPolygon() |
||
| 702 | * @see http://docs.mongodb.org/manual/reference/operator/polygon/ |
||
| 703 | * @param array $point1 First point of the polygon |
||
| 704 | * @param array $point2 Second point of the polygon |
||
| 705 | * @param array $point3 Third point of the polygon |
||
| 706 | * @param array ...$points Additional points of the polygon |
||
| 707 | * @return $this |
||
| 708 | */ |
||
| 709 | 1 | public function geoWithinPolygon($point1, $point2, $point3, ...$points) |
|
| 714 | |||
| 715 | /** |
||
| 716 | * Return the expression's "new object". |
||
| 717 | * |
||
| 718 | * @see Expr::getNewObj() |
||
| 719 | * @return array |
||
| 720 | */ |
||
| 721 | 13 | public function getNewObj() |
|
| 725 | |||
| 726 | /** |
||
| 727 | * Gets the Query executable. |
||
| 728 | * |
||
| 729 | * @param array $options |
||
| 730 | * @return Query $query |
||
| 731 | */ |
||
| 732 | 150 | public function getQuery(array $options = []) |
|
| 733 | { |
||
| 734 | 150 | if ($this->query['type'] === Query::TYPE_MAP_REDUCE) { |
|
| 735 | $this->hydrate = false; |
||
| 736 | } |
||
| 737 | |||
| 738 | 150 | $documentPersister = $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name); |
|
| 739 | |||
| 740 | 150 | $query = $this->query; |
|
| 741 | |||
| 742 | 150 | $query['query'] = $this->expr->getQuery(); |
|
| 743 | 150 | $query['query'] = $documentPersister->addDiscriminatorToPreparedQuery($query['query']); |
|
| 744 | 150 | $query['query'] = $documentPersister->addFilterToPreparedQuery($query['query']); |
|
| 745 | |||
| 746 | 150 | $query['newObj'] = $this->expr->getNewObj(); |
|
| 747 | |||
| 748 | 150 | if (isset($query['distinct'])) { |
|
| 749 | 2 | $query['distinct'] = $documentPersister->prepareFieldName($query['distinct']); |
|
| 750 | } |
||
| 751 | |||
| 752 | 150 | if ($this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION && ! empty($query['upsert']) && |
|
| 753 | 150 | (empty($query['query'][$this->class->discriminatorField]) || is_array($query['query'][$this->class->discriminatorField]))) { |
|
| 754 | 1 | throw new \InvalidArgumentException('Upsert query that is to be performed on discriminated document does not have single ' . |
|
| 755 | 1 | 'discriminator. Either not use base class or set \'' . $this->class->discriminatorField . '\' field manually.'); |
|
| 756 | } |
||
| 757 | |||
| 758 | 149 | if (! empty($query['select'])) { |
|
| 759 | 14 | $query['select'] = $documentPersister->prepareProjection($query['select']); |
|
| 760 | 14 | if ($this->hydrate && $this->class->inheritanceType === ClassMetadata::INHERITANCE_TYPE_SINGLE_COLLECTION |
|
| 761 | 14 | && ! isset($query['select'][$this->class->discriminatorField])) { |
|
| 762 | $includeMode = 0 < count(array_filter($query['select'], function ($mode) { |
||
| 763 | 2 | return $mode === 1; |
|
| 764 | 2 | })); |
|
| 765 | 2 | if ($includeMode && ! isset($query['select'][$this->class->discriminatorField])) { |
|
| 766 | 1 | $query['select'][$this->class->discriminatorField] = 1; |
|
| 767 | } |
||
| 768 | } |
||
| 769 | } |
||
| 770 | |||
| 771 | 149 | if (isset($query['sort'])) { |
|
| 772 | 23 | $query['sort'] = $documentPersister->prepareSort($query['sort']); |
|
| 773 | } |
||
| 774 | |||
| 775 | 149 | if ($this->class->readPreference && ! array_key_exists('readPreference', $query)) { |
|
| 776 | 1 | $query['readPreference'] = new ReadPreference($this->class->readPreference, $this->class->readPreferenceTags); |
|
| 777 | } |
||
| 778 | |||
| 779 | 149 | return new Query( |
|
| 780 | 149 | $this->dm, |
|
| 781 | 149 | $this->class, |
|
| 782 | 149 | $this->collection, |
|
| 783 | 149 | $query, |
|
| 784 | 149 | $options, |
|
| 785 | 149 | $this->hydrate, |
|
| 786 | 149 | $this->refresh, |
|
| 787 | 149 | $this->primers, |
|
| 788 | 149 | $this->readOnly |
|
| 789 | ); |
||
| 790 | } |
||
| 791 | |||
| 792 | /** |
||
| 793 | * Return the expression's query criteria. |
||
| 794 | * |
||
| 795 | * @see Expr::getQuery() |
||
| 796 | * @return array |
||
| 797 | */ |
||
| 798 | 33 | public function getQueryArray() |
|
| 802 | |||
| 803 | /** |
||
| 804 | * Get the type of this query. |
||
| 805 | * |
||
| 806 | * @return int $type |
||
| 807 | */ |
||
| 808 | 2 | public function getType() |
|
| 812 | |||
| 813 | /** |
||
| 814 | * Specify $gt criteria for the current field. |
||
| 815 | * |
||
| 816 | * @see Expr::gt() |
||
| 817 | * @see http://docs.mongodb.org/manual/reference/operator/gt/ |
||
| 818 | * @param mixed $value |
||
| 819 | * @return $this |
||
| 820 | */ |
||
| 821 | 2 | public function gt($value) |
|
| 826 | |||
| 827 | /** |
||
| 828 | * Specify $gte criteria for the current field. |
||
| 829 | * |
||
| 830 | * @see Expr::gte() |
||
| 831 | * @see http://docs.mongodb.org/manual/reference/operator/gte/ |
||
| 832 | * @param mixed $value |
||
| 833 | * @return $this |
||
| 834 | */ |
||
| 835 | 2 | public function gte($value) |
|
| 840 | |||
| 841 | /** |
||
| 842 | * Set the index hint for the query. |
||
| 843 | * |
||
| 844 | * @param array|string $index |
||
| 845 | * @return $this |
||
| 846 | */ |
||
| 847 | public function hint($index) |
||
| 852 | |||
| 853 | /** |
||
| 854 | * @param bool $bool |
||
| 855 | * @return $this |
||
| 856 | */ |
||
| 857 | 17 | public function hydrate($bool = true) |
|
| 862 | |||
| 863 | /** |
||
| 864 | * Set the immortal cursor flag. |
||
| 865 | * |
||
| 866 | * @param bool $bool |
||
| 867 | * @return $this |
||
| 868 | */ |
||
| 869 | public function immortal($bool = true) |
||
| 874 | |||
| 875 | /** |
||
| 876 | * Specify $in criteria for the current field. |
||
| 877 | * |
||
| 878 | * @see Expr::in() |
||
| 879 | * @see http://docs.mongodb.org/manual/reference/operator/in/ |
||
| 880 | * @param array $values |
||
| 881 | * @return $this |
||
| 882 | */ |
||
| 883 | 24 | public function in(array $values) |
|
| 888 | |||
| 889 | /** |
||
| 890 | * Increment the current field. |
||
| 891 | * |
||
| 892 | * If the field does not exist, it will be set to this value. |
||
| 893 | * |
||
| 894 | * @see Expr::inc() |
||
| 895 | * @see http://docs.mongodb.org/manual/reference/operator/inc/ |
||
| 896 | * @param float|int $value |
||
| 897 | * @return $this |
||
| 898 | */ |
||
| 899 | 6 | public function inc($value) |
|
| 904 | |||
| 905 | /** |
||
| 906 | * @param object $document |
||
| 907 | * @return $this |
||
| 908 | */ |
||
| 909 | 6 | public function includesReferenceTo($document) |
|
| 914 | |||
| 915 | /** |
||
| 916 | * @param string $documentName |
||
| 917 | * @return $this |
||
| 918 | */ |
||
| 919 | 1 | public function insert($documentName = null) |
|
| 926 | |||
| 927 | /** |
||
| 928 | * Set the $language option for $text criteria. |
||
| 929 | * |
||
| 930 | * This method must be called after text(). |
||
| 931 | * |
||
| 932 | * @see Expr::language() |
||
| 933 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 934 | * @param string $language |
||
| 935 | * @return $this |
||
| 936 | */ |
||
| 937 | 1 | public function language($language) |
|
| 942 | |||
| 943 | /** |
||
| 944 | * Set the limit for the query. |
||
| 945 | * |
||
| 946 | * This is only relevant for find queries and geoNear and mapReduce |
||
| 947 | * commands. |
||
| 948 | * |
||
| 949 | * @see Query::prepareCursor() |
||
| 950 | * @param int $limit |
||
| 951 | * @return $this |
||
| 952 | */ |
||
| 953 | 2 | public function limit($limit) |
|
| 958 | |||
| 959 | /** |
||
| 960 | * Specify $lt criteria for the current field. |
||
| 961 | * |
||
| 962 | * @see Expr::lte() |
||
| 963 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
| 964 | * @param mixed $value |
||
| 965 | * @return $this |
||
| 966 | */ |
||
| 967 | public function lt($value) |
||
| 972 | |||
| 973 | /** |
||
| 974 | * Specify $lte criteria for the current field. |
||
| 975 | * |
||
| 976 | * @see Expr::lte() |
||
| 977 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
| 978 | * @param mixed $value |
||
| 979 | * @return $this |
||
| 980 | */ |
||
| 981 | public function lte($value) |
||
| 986 | |||
| 987 | /** |
||
| 988 | * Change the query type to a mapReduce command. |
||
| 989 | * |
||
| 990 | * The "reduce" option is not specified when calling this method; it must |
||
| 991 | * be set with the {@link Builder::reduce()} method. |
||
| 992 | * |
||
| 993 | * The "out" option defaults to inline, like {@link Builder::mapReduce()}. |
||
| 994 | * |
||
| 995 | * @see http://docs.mongodb.org/manual/reference/command/mapReduce/ |
||
| 996 | * @param string|Javascript $map |
||
| 997 | * @return $this |
||
| 998 | */ |
||
| 999 | 1 | public function map($map) |
|
| 1010 | |||
| 1011 | /** |
||
| 1012 | * Change the query type to a mapReduce command. |
||
| 1013 | * |
||
| 1014 | * @see http://docs.mongodb.org/manual/reference/command/mapReduce/ |
||
| 1015 | * @param string|Javascript $map |
||
| 1016 | * @param string|Javascript $reduce |
||
| 1017 | * @param array|string $out |
||
| 1018 | * @param array $options |
||
| 1019 | * @return $this |
||
| 1020 | */ |
||
| 1021 | 1 | public function mapReduce($map, $reduce, $out = ['inline' => true], array $options = []) |
|
| 1032 | |||
| 1033 | /** |
||
| 1034 | * Set additional options for a mapReduce command. |
||
| 1035 | * |
||
| 1036 | * @param array $options |
||
| 1037 | * @return $this |
||
| 1038 | * @throws \BadMethodCallException If the query is not a mapReduce command. |
||
| 1039 | */ |
||
| 1040 | 1 | View Code Duplication | public function mapReduceOptions(array $options) |
| 1049 | |||
| 1050 | /** |
||
| 1051 | * Updates the value of the field to a specified value if the specified value is greater than the current value of the field. |
||
| 1052 | * |
||
| 1053 | * @see Expr::max() |
||
| 1054 | * @see http://docs.mongodb.org/manual/reference/operator/update/max/ |
||
| 1055 | * @param mixed $value |
||
| 1056 | * @return $this |
||
| 1057 | */ |
||
| 1058 | 1 | public function max($value) |
|
| 1063 | |||
| 1064 | /** |
||
| 1065 | * Specifies a cumulative time limit in milliseconds for processing operations on a cursor. |
||
| 1066 | * |
||
| 1067 | * @param int $ms |
||
| 1068 | * @return $this |
||
| 1069 | */ |
||
| 1070 | public function maxTimeMS($ms) |
||
| 1075 | |||
| 1076 | /** |
||
| 1077 | * Updates the value of the field to a specified value if the specified value is less than the current value of the field. |
||
| 1078 | * |
||
| 1079 | * @see Expr::min() |
||
| 1080 | * @see http://docs.mongodb.org/manual/reference/operator/update/min/ |
||
| 1081 | * @param mixed $value |
||
| 1082 | * @return $this |
||
| 1083 | */ |
||
| 1084 | 1 | public function min($value) |
|
| 1089 | |||
| 1090 | /** |
||
| 1091 | * Specify $mod criteria for the current field. |
||
| 1092 | * |
||
| 1093 | * @see Expr::mod() |
||
| 1094 | * @see http://docs.mongodb.org/manual/reference/operator/mod/ |
||
| 1095 | * @param float|int $divisor |
||
| 1096 | * @param float|int $remainder |
||
| 1097 | * @return $this |
||
| 1098 | */ |
||
| 1099 | 1 | public function mod($divisor, $remainder = 0) |
|
| 1104 | |||
| 1105 | /** |
||
| 1106 | * Multiply the current field. |
||
| 1107 | * |
||
| 1108 | * If the field does not exist, it will be set to 0. |
||
| 1109 | * |
||
| 1110 | * @see Expr::mul() |
||
| 1111 | * @see http://docs.mongodb.org/manual/reference/operator/mul/ |
||
| 1112 | * @param float|int $value |
||
| 1113 | * @return $this |
||
| 1114 | */ |
||
| 1115 | 1 | public function mul($value) |
|
| 1120 | |||
| 1121 | /** |
||
| 1122 | * Add $near criteria to the query. |
||
| 1123 | * |
||
| 1124 | * A GeoJSON point may be provided as the first and only argument for |
||
| 1125 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
| 1126 | * an array corresponding to the point's JSON representation. |
||
| 1127 | * |
||
| 1128 | * @see Expr::near() |
||
| 1129 | * @see http://docs.mongodb.org/manual/reference/operator/near/ |
||
| 1130 | * @param float|array|Point $x |
||
| 1131 | * @param float $y |
||
| 1132 | * @return $this |
||
| 1133 | */ |
||
| 1134 | 1 | public function near($x, $y = null) |
|
| 1139 | |||
| 1140 | /** |
||
| 1141 | * Add $nearSphere criteria to the query. |
||
| 1142 | * |
||
| 1143 | * A GeoJSON point may be provided as the first and only argument for |
||
| 1144 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
| 1145 | * an array corresponding to the point's JSON representation. |
||
| 1146 | * |
||
| 1147 | * @see Expr::nearSphere() |
||
| 1148 | * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/ |
||
| 1149 | * @param float|array|Point $x |
||
| 1150 | * @param float $y |
||
| 1151 | * @return $this |
||
| 1152 | */ |
||
| 1153 | 1 | public function nearSphere($x, $y = null) |
|
| 1158 | |||
| 1159 | /** |
||
| 1160 | * Negates an expression for the current field. |
||
| 1161 | * |
||
| 1162 | * You can create a new expression using the {@link Builder::expr()} method. |
||
| 1163 | * |
||
| 1164 | * @see Expr::not() |
||
| 1165 | * @see http://docs.mongodb.org/manual/reference/operator/not/ |
||
| 1166 | * @param array|Expr $expression |
||
| 1167 | * @return $this |
||
| 1168 | */ |
||
| 1169 | 3 | public function not($expression) |
|
| 1174 | |||
| 1175 | /** |
||
| 1176 | * Specify $ne criteria for the current field. |
||
| 1177 | * |
||
| 1178 | * @see Expr::notEqual() |
||
| 1179 | * @see http://docs.mongodb.org/manual/reference/operator/ne/ |
||
| 1180 | * @param mixed $value |
||
| 1181 | * @return $this |
||
| 1182 | */ |
||
| 1183 | 4 | public function notEqual($value) |
|
| 1188 | |||
| 1189 | /** |
||
| 1190 | * Specify $nin criteria for the current field. |
||
| 1191 | * |
||
| 1192 | * @see Expr::notIn() |
||
| 1193 | * @see http://docs.mongodb.org/manual/reference/operator/nin/ |
||
| 1194 | * @param array $values |
||
| 1195 | * @return $this |
||
| 1196 | */ |
||
| 1197 | 4 | public function notIn(array $values) |
|
| 1202 | |||
| 1203 | /** |
||
| 1204 | * Set the "out" option for a mapReduce command. |
||
| 1205 | * |
||
| 1206 | * @param array|string $out |
||
| 1207 | * @return $this |
||
| 1208 | * @throws \BadMethodCallException If the query is not a mapReduce command. |
||
| 1209 | */ |
||
| 1210 | 1 | View Code Duplication | public function out($out) |
| 1219 | |||
| 1220 | /** |
||
| 1221 | * Remove the first element from the current array field. |
||
| 1222 | * |
||
| 1223 | * @see Expr::popFirst() |
||
| 1224 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
| 1225 | * @return $this |
||
| 1226 | */ |
||
| 1227 | 2 | public function popFirst() |
|
| 1232 | |||
| 1233 | /** |
||
| 1234 | * Remove the last element from the current array field. |
||
| 1235 | * |
||
| 1236 | * @see Expr::popLast() |
||
| 1237 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
| 1238 | * @return $this |
||
| 1239 | */ |
||
| 1240 | 1 | public function popLast() |
|
| 1245 | |||
| 1246 | /** |
||
| 1247 | * Use a primer to eagerly load all references in the current field. |
||
| 1248 | * |
||
| 1249 | * If $primer is true or a callable is provided, referenced documents for |
||
| 1250 | * this field will loaded into UnitOfWork immediately after the query is |
||
| 1251 | * executed. This will avoid multiple queries due to lazy initialization of |
||
| 1252 | * Proxy objects. |
||
| 1253 | * |
||
| 1254 | * If $primer is false, no priming will take place. That is also the default |
||
| 1255 | * behavior. |
||
| 1256 | * |
||
| 1257 | * If a custom callable is used, its signature should conform to the default |
||
| 1258 | * Closure defined in {@link ReferencePrimer::__construct()}. |
||
| 1259 | * |
||
| 1260 | * @param bool|callable $primer |
||
| 1261 | * @return $this |
||
| 1262 | * @throws \InvalidArgumentException If $primer is not boolean or callable. |
||
| 1263 | */ |
||
| 1264 | 25 | public function prime($primer = true) |
|
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Remove all elements matching the given value or expression from the |
||
| 1286 | * current array field. |
||
| 1287 | * |
||
| 1288 | * @see Expr::pull() |
||
| 1289 | * @see http://docs.mongodb.org/manual/reference/operator/pull/ |
||
| 1290 | * @param mixed|Expr $valueOrExpression |
||
| 1291 | * @return $this |
||
| 1292 | */ |
||
| 1293 | 1 | public function pull($valueOrExpression) |
|
| 1298 | |||
| 1299 | /** |
||
| 1300 | * Remove all elements matching any of the given values from the current |
||
| 1301 | * array field. |
||
| 1302 | * |
||
| 1303 | * @see Expr::pullAll() |
||
| 1304 | * @see http://docs.mongodb.org/manual/reference/operator/pullAll/ |
||
| 1305 | * @param array $values |
||
| 1306 | * @return $this |
||
| 1307 | */ |
||
| 1308 | 1 | public function pullAll(array $values) |
|
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Append one or more values to the current array field. |
||
| 1316 | * |
||
| 1317 | * If the field does not exist, it will be set to an array containing the |
||
| 1318 | * value(s) in the argument. If the field is not an array, the query |
||
| 1319 | * will yield an error. |
||
| 1320 | * |
||
| 1321 | * Multiple values may be specified by providing an Expr object and using |
||
| 1322 | * {@link Expr::each()}. {@link Expr::slice()} and {@link Expr::sort()} may |
||
| 1323 | * also be used to limit and order array elements, respectively. |
||
| 1324 | * |
||
| 1325 | * @see Expr::push() |
||
| 1326 | * @see http://docs.mongodb.org/manual/reference/operator/push/ |
||
| 1327 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 1328 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
| 1329 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
| 1330 | * @param mixed|Expr $valueOrExpression |
||
| 1331 | * @return $this |
||
| 1332 | */ |
||
| 1333 | 6 | public function push($valueOrExpression) |
|
| 1338 | |||
| 1339 | /** |
||
| 1340 | * Specify $gte and $lt criteria for the current field. |
||
| 1341 | * |
||
| 1342 | * This method is shorthand for specifying $gte criteria on the lower bound |
||
| 1343 | * and $lt criteria on the upper bound. The upper bound is not inclusive. |
||
| 1344 | * |
||
| 1345 | * @see Expr::range() |
||
| 1346 | * @param mixed $start |
||
| 1347 | * @param mixed $end |
||
| 1348 | * @return $this |
||
| 1349 | */ |
||
| 1350 | 3 | public function range($start, $end) |
|
| 1355 | |||
| 1356 | /** |
||
| 1357 | * @param bool $bool |
||
| 1358 | * @return $this |
||
| 1359 | */ |
||
| 1360 | 2 | public function readOnly($bool = true) |
|
| 1365 | |||
| 1366 | /** |
||
| 1367 | * Set the "reduce" option for a mapReduce or group command. |
||
| 1368 | * |
||
| 1369 | * @param string|Javascript $reduce |
||
| 1370 | * @return $this |
||
| 1371 | * @throws \BadMethodCallException If the query is not a mapReduce or group command. |
||
| 1372 | */ |
||
| 1373 | 2 | View Code Duplication | public function reduce($reduce) |
| 1390 | |||
| 1391 | /** |
||
| 1392 | * @param object $document |
||
| 1393 | * @return $this |
||
| 1394 | */ |
||
| 1395 | 10 | public function references($document) |
|
| 1400 | |||
| 1401 | /** |
||
| 1402 | * @param bool $bool |
||
| 1403 | * @return $this |
||
| 1404 | */ |
||
| 1405 | 5 | public function refresh($bool = true) |
|
| 1410 | |||
| 1411 | /** |
||
| 1412 | * @param string $documentName |
||
| 1413 | * @return $this |
||
| 1414 | */ |
||
| 1415 | 1 | public function remove($documentName = null) |
|
| 1422 | |||
| 1423 | /** |
||
| 1424 | * Rename the current field. |
||
| 1425 | * |
||
| 1426 | * @see Expr::rename() |
||
| 1427 | * @see http://docs.mongodb.org/manual/reference/operator/rename/ |
||
| 1428 | * @param string $name |
||
| 1429 | * @return $this |
||
| 1430 | */ |
||
| 1431 | public function rename($name) |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * @param bool $bool |
||
| 1439 | * @return $this |
||
| 1440 | */ |
||
| 1441 | 4 | public function returnNew($bool = true) |
|
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Set one or more fields to be included in the query projection. |
||
| 1451 | * |
||
| 1452 | * @param array|string $fieldName,... |
||
| 1453 | * @return $this |
||
| 1454 | */ |
||
| 1455 | 19 | View Code Duplication | public function select($fieldName = null) |
| 1469 | |||
| 1470 | /** |
||
| 1471 | * Select only matching embedded documents in an array field for the query |
||
| 1472 | * projection. |
||
| 1473 | * |
||
| 1474 | * @see http://docs.mongodb.org/manual/reference/projection/elemMatch/ |
||
| 1475 | * @param string $fieldName |
||
| 1476 | * @param array|Expr $expression |
||
| 1477 | * @return $this |
||
| 1478 | */ |
||
| 1479 | 2 | public function selectElemMatch($fieldName, $expression) |
|
| 1487 | |||
| 1488 | /** |
||
| 1489 | * Select a metadata field for the query projection. |
||
| 1490 | * |
||
| 1491 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/ |
||
| 1492 | * @param string $fieldName |
||
| 1493 | * @param string $metaDataKeyword |
||
| 1494 | * @return $this |
||
| 1495 | */ |
||
| 1496 | 2 | public function selectMeta($fieldName, $metaDataKeyword) |
|
| 1501 | |||
| 1502 | /** |
||
| 1503 | * Select a slice of an array field for the query projection. |
||
| 1504 | * |
||
| 1505 | * The $countOrSkip parameter has two very different meanings, depending on |
||
| 1506 | * whether or not $limit is provided. See the MongoDB documentation for more |
||
| 1507 | * information. |
||
| 1508 | * |
||
| 1509 | * @see http://docs.mongodb.org/manual/reference/projection/slice/ |
||
| 1510 | * @param string $fieldName |
||
| 1511 | * @param int $countOrSkip Count parameter, or skip if limit is specified |
||
| 1512 | * @param int $limit Limit parameter used in conjunction with skip |
||
| 1513 | * @return $this |
||
| 1514 | */ |
||
| 1515 | 3 | public function selectSlice($fieldName, $countOrSkip, $limit = null) |
|
| 1524 | |||
| 1525 | /** |
||
| 1526 | * Set the current field to a value. |
||
| 1527 | * |
||
| 1528 | * This is only relevant for insert, update, or findAndUpdate queries. For |
||
| 1529 | * update and findAndUpdate queries, the $atomic parameter will determine |
||
| 1530 | * whether or not a $set operator is used. |
||
| 1531 | * |
||
| 1532 | * @see Expr::set() |
||
| 1533 | * @see http://docs.mongodb.org/manual/reference/operator/set/ |
||
| 1534 | * @param mixed $value |
||
| 1535 | * @param bool $atomic |
||
| 1536 | * @return $this |
||
| 1537 | */ |
||
| 1538 | 16 | public function set($value, $atomic = true) |
|
| 1543 | |||
| 1544 | /** |
||
| 1545 | * Set the expression's "new object". |
||
| 1546 | * |
||
| 1547 | * @see Expr::setNewObj() |
||
| 1548 | * @param array $newObj |
||
| 1549 | * @return $this |
||
| 1550 | */ |
||
| 1551 | public function setNewObj(array $newObj) |
||
| 1556 | |||
| 1557 | /** |
||
| 1558 | * Set the current field to the value if the document is inserted in an |
||
| 1559 | * upsert operation. |
||
| 1560 | * |
||
| 1561 | * If an update operation with upsert: true results in an insert of a |
||
| 1562 | * document, then $setOnInsert assigns the specified values to the fields in |
||
| 1563 | * the document. If the update operation does not result in an insert, |
||
| 1564 | * $setOnInsert does nothing. |
||
| 1565 | * |
||
| 1566 | * @see Expr::setOnInsert() |
||
| 1567 | * @see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ |
||
| 1568 | * @param mixed $value |
||
| 1569 | * @return $this |
||
| 1570 | */ |
||
| 1571 | 2 | public function setOnInsert($value) |
|
| 1576 | |||
| 1577 | /** |
||
| 1578 | * Set the read preference for the query. |
||
| 1579 | * |
||
| 1580 | * This is only relevant for read-only queries and commands. |
||
| 1581 | * |
||
| 1582 | * @see http://docs.mongodb.org/manual/core/read-preference/ |
||
| 1583 | * @return $this |
||
| 1584 | */ |
||
| 1585 | 6 | public function setReadPreference(ReadPreference $readPreference) |
|
| 1590 | |||
| 1591 | /** |
||
| 1592 | * Set the expression's query criteria. |
||
| 1593 | * |
||
| 1594 | * @see Expr::setQuery() |
||
| 1595 | * @param array $query |
||
| 1596 | * @return $this |
||
| 1597 | */ |
||
| 1598 | 18 | public function setQueryArray(array $query) |
|
| 1603 | |||
| 1604 | /** |
||
| 1605 | * Specify $size criteria for the current field. |
||
| 1606 | * |
||
| 1607 | * @see Expr::size() |
||
| 1608 | * @see http://docs.mongodb.org/manual/reference/operator/size/ |
||
| 1609 | * @param int $size |
||
| 1610 | * @return $this |
||
| 1611 | */ |
||
| 1612 | 1 | public function size($size) |
|
| 1617 | |||
| 1618 | /** |
||
| 1619 | * Set the skip for the query cursor. |
||
| 1620 | * |
||
| 1621 | * This is only relevant for find queries, or mapReduce queries that store |
||
| 1622 | * results in an output collecton and return a cursor. |
||
| 1623 | * |
||
| 1624 | * @see Query::prepareCursor() |
||
| 1625 | * @param int $skip |
||
| 1626 | * @return $this |
||
| 1627 | */ |
||
| 1628 | public function skip($skip) |
||
| 1633 | |||
| 1634 | /** |
||
| 1635 | * Set the snapshot cursor flag. |
||
| 1636 | * |
||
| 1637 | * @param bool $bool |
||
| 1638 | * @return $this |
||
| 1639 | */ |
||
| 1640 | public function snapshot($bool = true) |
||
| 1645 | |||
| 1646 | /** |
||
| 1647 | * Set one or more field/order pairs on which to sort the query. |
||
| 1648 | * |
||
| 1649 | * If sorting by multiple fields, the first argument should be an array of |
||
| 1650 | * field name (key) and order (value) pairs. |
||
| 1651 | * |
||
| 1652 | * @param array|string $fieldName Field name or array of field/order pairs |
||
| 1653 | * @param int|string $order Field order (if one field is specified) |
||
| 1654 | * @return $this |
||
| 1655 | */ |
||
| 1656 | 31 | public function sort($fieldName, $order = 1) |
|
| 1673 | |||
| 1674 | /** |
||
| 1675 | * Specify a projected metadata field on which to sort the query. |
||
| 1676 | * |
||
| 1677 | * Sort order is not configurable for metadata fields. Sorting by a metadata |
||
| 1678 | * field requires the same field and $meta expression to exist in the |
||
| 1679 | * projection document. This method will call {@link Builder::selectMeta()} |
||
| 1680 | * if the field is not already set in the projection. |
||
| 1681 | * |
||
| 1682 | * @see http://docs.mongodb.org/master/reference/operator/projection/meta/#sort |
||
| 1683 | * @param string $fieldName Field name of the projected metadata |
||
| 1684 | * @param string $metaDataKeyword |
||
| 1685 | * @return $this |
||
| 1686 | */ |
||
| 1687 | 2 | public function sortMeta($fieldName, $metaDataKeyword) |
|
| 1701 | |||
| 1702 | /** |
||
| 1703 | * Specify $text criteria for the current field. |
||
| 1704 | * |
||
| 1705 | * The $language option may be set with {@link Builder::language()}. |
||
| 1706 | * |
||
| 1707 | * @see Expr::text() |
||
| 1708 | * @see http://docs.mongodb.org/master/reference/operator/query/text/ |
||
| 1709 | * @param string $search |
||
| 1710 | * @return $this |
||
| 1711 | */ |
||
| 1712 | 1 | public function text($search) |
|
| 1717 | |||
| 1718 | /** |
||
| 1719 | * Specify $type criteria for the current field. |
||
| 1720 | * |
||
| 1721 | * @see Expr::type() |
||
| 1722 | * @see http://docs.mongodb.org/manual/reference/operator/type/ |
||
| 1723 | * @param int $type |
||
| 1724 | * @return $this |
||
| 1725 | */ |
||
| 1726 | 2 | public function type($type) |
|
| 1731 | |||
| 1732 | /** |
||
| 1733 | * Unset the current field. |
||
| 1734 | * |
||
| 1735 | * The field will be removed from the document (not set to null). |
||
| 1736 | * |
||
| 1737 | * @see Expr::unsetField() |
||
| 1738 | * @see http://docs.mongodb.org/manual/reference/operator/unset/ |
||
| 1739 | * @return $this |
||
| 1740 | */ |
||
| 1741 | 4 | public function unsetField() |
|
| 1746 | |||
| 1747 | /** |
||
| 1748 | * @param string $documentName |
||
| 1749 | * @return $this |
||
| 1750 | */ |
||
| 1751 | 21 | View Code Duplication | public function updateOne($documentName = null) |
| 1759 | |||
| 1760 | /** |
||
| 1761 | * @param string $documentName |
||
| 1762 | * @return $this |
||
| 1763 | */ |
||
| 1764 | 3 | View Code Duplication | public function updateMany($documentName = null) |
| 1772 | |||
| 1773 | /** |
||
| 1774 | * Set the "upsert" option for an update or findAndUpdate query. |
||
| 1775 | * |
||
| 1776 | * @param bool $bool |
||
| 1777 | * @return $this |
||
| 1778 | */ |
||
| 1779 | 7 | public function upsert($bool = true) |
|
| 1784 | |||
| 1785 | /** |
||
| 1786 | * Specify a JavaScript expression to use for matching documents. |
||
| 1787 | * |
||
| 1788 | * @see Expr::where() |
||
| 1789 | * @see http://docs.mongodb.org/manual/reference/operator/where/ |
||
| 1790 | * @param string|Javascript $javascript |
||
| 1791 | * @return $this |
||
| 1792 | */ |
||
| 1793 | 3 | public function where($javascript) |
|
| 1798 | |||
| 1799 | /** |
||
| 1800 | * Get Discriminator Values |
||
| 1801 | * |
||
| 1802 | * @param \Traversable $classNames |
||
| 1803 | * @return array an array of discriminatorValues (mixed type) |
||
| 1804 | * @throws \InvalidArgumentException If the number of found collections > 1. |
||
| 1805 | */ |
||
| 1806 | 2 | private function getDiscriminatorValues($classNames) |
|
| 1821 | |||
| 1822 | /** |
||
| 1823 | * @param string[]|string $documentName an array of document names or just one. |
||
| 1824 | */ |
||
| 1825 | 284 | private function setDocumentName($documentName) |
|
| 1853 | } |
||
| 1854 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.