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 Expr 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 Expr, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | class Expr |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * The query criteria array. |
||
| 36 | * |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | private $query = []; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The "new object" array containing either a full document or a number of |
||
| 43 | * atomic update operators. |
||
| 44 | * |
||
| 45 | * @see docs.mongodb.org/manual/reference/method/db.collection.update/#update-parameter |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | private $newObj = []; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The current field we are operating on. |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | private $currentField; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * The DocumentManager instance for this query |
||
| 59 | * |
||
| 60 | * @var DocumentManager |
||
| 61 | */ |
||
| 62 | private $dm; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * The ClassMetadata instance for the document being queried |
||
| 66 | * |
||
| 67 | * @var ClassMetadata |
||
| 68 | */ |
||
| 69 | private $class; |
||
| 70 | |||
| 71 | 395 | public function __construct(DocumentManager $dm) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Add one or more $and clauses to the current query. |
||
| 78 | * |
||
| 79 | * @see Builder::addAnd() |
||
| 80 | * @see http://docs.mongodb.org/manual/reference/operator/and/ |
||
| 81 | * @param array|Expr $expression |
||
| 82 | * @param array|Expr ...$expressions |
||
| 83 | * @return $this |
||
| 84 | */ |
||
| 85 | 3 | View Code Duplication | public function addAnd($expression, ...$expressions) |
| 103 | |||
| 104 | /** |
||
| 105 | * Add one or more $nor clauses to the current query. |
||
| 106 | * |
||
| 107 | * @see Builder::addNor() |
||
| 108 | * @see http://docs.mongodb.org/manual/reference/operator/nor/ |
||
| 109 | * @param array|Expr $expression |
||
| 110 | * @param array|Expr ...$expressions |
||
| 111 | * @return $this |
||
| 112 | */ |
||
| 113 | 1 | View Code Duplication | public function addNor($expression, ...$expressions) |
| 128 | |||
| 129 | /** |
||
| 130 | * Add one or more $or clauses to the current query. |
||
| 131 | * |
||
| 132 | * @see Builder::addOr() |
||
| 133 | * @see http://docs.mongodb.org/manual/reference/operator/or/ |
||
| 134 | * @param array|Expr $expression |
||
| 135 | * @param array|Expr ...$expressions |
||
| 136 | * @return $this |
||
| 137 | */ |
||
| 138 | 5 | View Code Duplication | public function addOr($expression, ...$expressions) |
| 153 | |||
| 154 | /** |
||
| 155 | * Append one or more values to the current array field only if they do not |
||
| 156 | * already exist in the array. |
||
| 157 | * |
||
| 158 | * If the field does not exist, it will be set to an array containing the |
||
| 159 | * unique value(s) in the argument. If the field is not an array, the query |
||
| 160 | * will yield an error. |
||
| 161 | * |
||
| 162 | * Multiple values may be specified by provided an Expr object and using |
||
| 163 | * {@link Expr::each()}. |
||
| 164 | * |
||
| 165 | * @see Builder::addToSet() |
||
| 166 | * @see http://docs.mongodb.org/manual/reference/operator/addToSet/ |
||
| 167 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 168 | * @param mixed|Expr $valueOrExpression |
||
| 169 | * @return $this |
||
| 170 | */ |
||
| 171 | 5 | View Code Duplication | public function addToSet($valueOrExpression) |
| 181 | |||
| 182 | /** |
||
| 183 | * Specify $all criteria for the current field. |
||
| 184 | * |
||
| 185 | * @see Builder::all() |
||
| 186 | * @see http://docs.mongodb.org/manual/reference/operator/all/ |
||
| 187 | * @param array $values |
||
| 188 | * @return $this |
||
| 189 | */ |
||
| 190 | 2 | public function all(array $values) |
|
| 194 | |||
| 195 | /** |
||
| 196 | * Apply a bitwise operation on the current field |
||
| 197 | * |
||
| 198 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 199 | * @param string $operator |
||
| 200 | * @param int $value |
||
| 201 | * @return $this |
||
| 202 | */ |
||
| 203 | 3 | protected function bit($operator, $value) |
|
| 209 | |||
| 210 | /** |
||
| 211 | * Apply a bitwise and operation on the current field. |
||
| 212 | * |
||
| 213 | * @see Builder::bitAnd() |
||
| 214 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 215 | * @param int $value |
||
| 216 | * @return $this |
||
| 217 | */ |
||
| 218 | 1 | public function bitAnd($value) |
|
| 222 | |||
| 223 | /** |
||
| 224 | * Apply a bitwise or operation on the current field. |
||
| 225 | * |
||
| 226 | * @see Builder::bitOr() |
||
| 227 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 228 | * @param int $value |
||
| 229 | * @return $this |
||
| 230 | */ |
||
| 231 | 1 | public function bitOr($value) |
|
| 235 | |||
| 236 | /** |
||
| 237 | * Matches documents where all of the bit positions given by the query are |
||
| 238 | * clear. |
||
| 239 | * |
||
| 240 | * @see Builder::bitsAllClear() |
||
| 241 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/ |
||
| 242 | * @param int|array|Binary $value |
||
| 243 | * @return $this |
||
| 244 | */ |
||
| 245 | public function bitsAllClear($value) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Matches documents where all of the bit positions given by the query are |
||
| 253 | * set. |
||
| 254 | * |
||
| 255 | * @see Builder::bitsAllSet() |
||
| 256 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllSet/ |
||
| 257 | * @param int|array|Binary $value |
||
| 258 | * @return $this |
||
| 259 | */ |
||
| 260 | public function bitsAllSet($value) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * Matches documents where any of the bit positions given by the query are |
||
| 268 | * clear. |
||
| 269 | * |
||
| 270 | * @see Builder::bitsAnyClear() |
||
| 271 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnyClear/ |
||
| 272 | * @param int|array|Binary $value |
||
| 273 | * @return $this |
||
| 274 | */ |
||
| 275 | public function bitsAnyClear($value) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Matches documents where any of the bit positions given by the query are |
||
| 283 | * set. |
||
| 284 | * |
||
| 285 | * @see Builder::bitsAnySet() |
||
| 286 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnySet/ |
||
| 287 | * @param int|array|Binary $value |
||
| 288 | * @return $this |
||
| 289 | */ |
||
| 290 | public function bitsAnySet($value) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * Apply a bitwise xor operation on the current field. |
||
| 298 | * |
||
| 299 | * @see Builder::bitXor() |
||
| 300 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 301 | * @param int $value |
||
| 302 | * @return $this |
||
| 303 | */ |
||
| 304 | 1 | public function bitXor($value) |
|
| 308 | |||
| 309 | /** |
||
| 310 | * A boolean flag to enable or disable case sensitive search for $text |
||
| 311 | * criteria. |
||
| 312 | * |
||
| 313 | * This method must be called after text(). |
||
| 314 | * |
||
| 315 | * @see Builder::caseSensitive() |
||
| 316 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 317 | * @param bool $caseSensitive |
||
| 318 | * @return $this |
||
| 319 | * @throws \BadMethodCallException If the query does not already have $text criteria. |
||
| 320 | * |
||
| 321 | */ |
||
| 322 | 3 | View Code Duplication | public function caseSensitive($caseSensitive) |
| 337 | |||
| 338 | /** |
||
| 339 | * Associates a comment to any expression taking a query predicate. |
||
| 340 | * |
||
| 341 | * @see Builder::comment() |
||
| 342 | * @see http://docs.mongodb.org/manual/reference/operator/query/comment/ |
||
| 343 | * @param string $comment |
||
| 344 | * @return $this |
||
| 345 | */ |
||
| 346 | public function comment($comment) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Sets the value of the current field to the current date, either as a date or a timestamp. |
||
| 354 | * |
||
| 355 | * @see Builder::currentDate() |
||
| 356 | * @see http://docs.mongodb.org/manual/reference/operator/update/currentDate/ |
||
| 357 | * @param string $type |
||
| 358 | * @return $this |
||
| 359 | * @throws \InvalidArgumentException If an invalid type is given. |
||
| 360 | */ |
||
| 361 | 3 | public function currentDate($type = 'date') |
|
| 371 | |||
| 372 | /** |
||
| 373 | * A boolean flag to enable or disable diacritic sensitive search for $text |
||
| 374 | * criteria. |
||
| 375 | * |
||
| 376 | * This method must be called after text(). |
||
| 377 | * |
||
| 378 | * @see Builder::diacriticSensitive() |
||
| 379 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 380 | * @param bool $diacriticSensitive |
||
| 381 | * @return $this |
||
| 382 | * @throws \BadMethodCallException If the query does not already have $text criteria. |
||
| 383 | * |
||
| 384 | */ |
||
| 385 | 3 | View Code Duplication | public function diacriticSensitive($diacriticSensitive) |
| 400 | |||
| 401 | /** |
||
| 402 | * Add $each criteria to the expression for a $push operation. |
||
| 403 | * |
||
| 404 | * @see Expr::push() |
||
| 405 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 406 | * @param array $values |
||
| 407 | * @return $this |
||
| 408 | */ |
||
| 409 | 4 | public function each(array $values) |
|
| 413 | |||
| 414 | /** |
||
| 415 | * Specify $elemMatch criteria for the current field. |
||
| 416 | * |
||
| 417 | * @see Builder::elemMatch() |
||
| 418 | * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/ |
||
| 419 | * @param array|Expr $expression |
||
| 420 | * @return $this |
||
| 421 | */ |
||
| 422 | 4 | public function elemMatch($expression) |
|
| 426 | |||
| 427 | /** |
||
| 428 | * Specify an equality match for the current field. |
||
| 429 | * |
||
| 430 | * @see Builder::equals() |
||
| 431 | * @param mixed $value |
||
| 432 | * @return $this |
||
| 433 | */ |
||
| 434 | 104 | public function equals($value) |
|
| 443 | |||
| 444 | /** |
||
| 445 | * Specify $exists criteria for the current field. |
||
| 446 | * |
||
| 447 | * @see Builder::exists() |
||
| 448 | * @see http://docs.mongodb.org/manual/reference/operator/exists/ |
||
| 449 | * @param bool $bool |
||
| 450 | * @return $this |
||
| 451 | */ |
||
| 452 | 5 | public function exists($bool) |
|
| 456 | |||
| 457 | /** |
||
| 458 | * Set the current field for building the expression. |
||
| 459 | * |
||
| 460 | * @see Builder::field() |
||
| 461 | * @param string $field |
||
| 462 | * @return $this |
||
| 463 | */ |
||
| 464 | 195 | public function field($field) |
|
| 469 | |||
| 470 | /** |
||
| 471 | * Add $geoIntersects criteria with a GeoJSON geometry to the expression. |
||
| 472 | * |
||
| 473 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
| 474 | * geometry's JSON representation. |
||
| 475 | * |
||
| 476 | * @see Builder::geoIntersects() |
||
| 477 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
| 478 | * @param array|Geometry $geometry |
||
| 479 | * @return $this |
||
| 480 | */ |
||
| 481 | 2 | View Code Duplication | public function geoIntersects($geometry) |
| 489 | |||
| 490 | /** |
||
| 491 | * Add $geoWithin criteria with a GeoJSON geometry to the expression. |
||
| 492 | * |
||
| 493 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
| 494 | * geometry's JSON representation. |
||
| 495 | * |
||
| 496 | * @see Builder::geoWithin() |
||
| 497 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
| 498 | * @param array|Geometry $geometry |
||
| 499 | * @return $this |
||
| 500 | */ |
||
| 501 | 2 | View Code Duplication | public function geoWithin($geometry) |
| 509 | |||
| 510 | /** |
||
| 511 | * Add $geoWithin criteria with a $box shape to the expression. |
||
| 512 | * |
||
| 513 | * A rectangular polygon will be constructed from a pair of coordinates |
||
| 514 | * corresponding to the bottom left and top right corners. |
||
| 515 | * |
||
| 516 | * Note: the $box operator only supports legacy coordinate pairs and 2d |
||
| 517 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 518 | * |
||
| 519 | * @see Builder::geoWithinBox() |
||
| 520 | * @see http://docs.mongodb.org/manual/reference/operator/box/ |
||
| 521 | * @param float $x1 |
||
| 522 | * @param float $y1 |
||
| 523 | * @param float $x2 |
||
| 524 | * @param float $y2 |
||
| 525 | * @return $this |
||
| 526 | */ |
||
| 527 | 1 | public function geoWithinBox($x1, $y1, $x2, $y2) |
|
| 533 | |||
| 534 | /** |
||
| 535 | * Add $geoWithin criteria with a $center shape to the expression. |
||
| 536 | * |
||
| 537 | * Note: the $center operator only supports legacy coordinate pairs and 2d |
||
| 538 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 539 | * |
||
| 540 | * @see Builider::geoWithinCenter() |
||
| 541 | * @see http://docs.mongodb.org/manual/reference/operator/center/ |
||
| 542 | * @param float $x |
||
| 543 | * @param float $y |
||
| 544 | * @param float $radius |
||
| 545 | * @return $this |
||
| 546 | */ |
||
| 547 | 1 | public function geoWithinCenter($x, $y, $radius) |
|
| 553 | |||
| 554 | /** |
||
| 555 | * Add $geoWithin criteria with a $centerSphere shape to the expression. |
||
| 556 | * |
||
| 557 | * Note: the $centerSphere operator supports both 2d and 2dsphere indexes. |
||
| 558 | * |
||
| 559 | * @see Builder::geoWithinCenterSphere() |
||
| 560 | * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/ |
||
| 561 | * @param float $x |
||
| 562 | * @param float $y |
||
| 563 | * @param float $radius |
||
| 564 | * @return $this |
||
| 565 | */ |
||
| 566 | 1 | public function geoWithinCenterSphere($x, $y, $radius) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Add $geoWithin criteria with a $polygon shape to the expression. |
||
| 575 | * |
||
| 576 | * Point coordinates are in x, y order (easting, northing for projected |
||
| 577 | * coordinates, longitude, latitude for geographic coordinates). |
||
| 578 | * |
||
| 579 | * The last point coordinate is implicitly connected with the first. |
||
| 580 | * |
||
| 581 | * Note: the $polygon operator only supports legacy coordinate pairs and 2d |
||
| 582 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 583 | * |
||
| 584 | * @see Builder::geoWithinPolygon() |
||
| 585 | * @see http://docs.mongodb.org/manual/reference/operator/polygon/ |
||
| 586 | * @param array $point1 First point of the polygon |
||
| 587 | * @param array $point2 Second point of the polygon |
||
| 588 | * @param array $point3 Third point of the polygon |
||
| 589 | * @param array ...$points Additional points of the polygon |
||
| 590 | * @return $this |
||
| 591 | * @throws \InvalidArgumentException If less than three points are given. |
||
| 592 | */ |
||
| 593 | 1 | public function geoWithinPolygon($point1, $point2, $point3, ...$points) |
|
| 599 | |||
| 600 | /** |
||
| 601 | * Return the current field. |
||
| 602 | * |
||
| 603 | * @return string |
||
| 604 | */ |
||
| 605 | 2 | public function getCurrentField() |
|
| 609 | |||
| 610 | /** |
||
| 611 | * Gets prepared newObj part of expression. |
||
| 612 | * |
||
| 613 | * @return array |
||
| 614 | */ |
||
| 615 | 178 | public function getNewObj() |
|
| 621 | |||
| 622 | /** |
||
| 623 | * Gets prepared query part of expression. |
||
| 624 | * |
||
| 625 | * @return array |
||
| 626 | */ |
||
| 627 | 254 | public function getQuery() |
|
| 633 | |||
| 634 | /** |
||
| 635 | * Specify $gt criteria for the current field. |
||
| 636 | * |
||
| 637 | * @see Builder::gt() |
||
| 638 | * @see http://docs.mongodb.org/manual/reference/operator/gt/ |
||
| 639 | * @param mixed $value |
||
| 640 | * @return $this |
||
| 641 | */ |
||
| 642 | 2 | public function gt($value) |
|
| 646 | |||
| 647 | /** |
||
| 648 | * Specify $gte criteria for the current field. |
||
| 649 | * |
||
| 650 | * @see Builder::gte() |
||
| 651 | * @see http://docs.mongodb.org/manual/reference/operator/gte/ |
||
| 652 | * @param mixed $value |
||
| 653 | * @return $this |
||
| 654 | */ |
||
| 655 | 2 | public function gte($value) |
|
| 659 | |||
| 660 | /** |
||
| 661 | * Specify $in criteria for the current field. |
||
| 662 | * |
||
| 663 | * @see Builder::in() |
||
| 664 | * @see http://docs.mongodb.org/manual/reference/operator/in/ |
||
| 665 | * @param array $values |
||
| 666 | * @return $this |
||
| 667 | */ |
||
| 668 | 31 | public function in(array $values) |
|
| 672 | |||
| 673 | /** |
||
| 674 | * Increment the current field. |
||
| 675 | * |
||
| 676 | * If the field does not exist, it will be set to this value. |
||
| 677 | * |
||
| 678 | * @see Builder::inc() |
||
| 679 | * @see http://docs.mongodb.org/manual/reference/operator/inc/ |
||
| 680 | * @param float|int $value |
||
| 681 | * @return $this |
||
| 682 | */ |
||
| 683 | 5 | public function inc($value) |
|
| 689 | |||
| 690 | /** |
||
| 691 | * Checks that the current field includes a reference to the supplied document. |
||
| 692 | * |
||
| 693 | * @param object $document |
||
| 694 | * @return Expr |
||
| 695 | */ |
||
| 696 | 6 | View Code Duplication | public function includesReferenceTo($document) |
| 737 | |||
| 738 | /** |
||
| 739 | * Set the $language option for $text criteria. |
||
| 740 | * |
||
| 741 | * This method must be called after text(). |
||
| 742 | * |
||
| 743 | * @see Builder::language() |
||
| 744 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 745 | * @param string $language |
||
| 746 | * @return $this |
||
| 747 | * @throws \BadMethodCallException If the query does not already have $text criteria. |
||
| 748 | */ |
||
| 749 | 2 | public function language($language) |
|
| 759 | |||
| 760 | /** |
||
| 761 | * Specify $lt criteria for the current field. |
||
| 762 | * |
||
| 763 | * @see Builder::lte() |
||
| 764 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
| 765 | * @param mixed $value |
||
| 766 | * @return $this |
||
| 767 | */ |
||
| 768 | 4 | public function lt($value) |
|
| 772 | |||
| 773 | /** |
||
| 774 | * Specify $lte criteria for the current field. |
||
| 775 | * |
||
| 776 | * @see Builder::lte() |
||
| 777 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
| 778 | * @param mixed $value |
||
| 779 | * @return $this |
||
| 780 | */ |
||
| 781 | 2 | public function lte($value) |
|
| 785 | |||
| 786 | /** |
||
| 787 | * Updates the value of the field to a specified value if the specified value is greater than the current value of the field. |
||
| 788 | * |
||
| 789 | * @see Builder::max() |
||
| 790 | * @see http://docs.mongodb.org/manual/reference/operator/update/max/ |
||
| 791 | * @param mixed $value |
||
| 792 | * @return $this |
||
| 793 | */ |
||
| 794 | public function max($value) |
||
| 800 | |||
| 801 | /** |
||
| 802 | * Updates the value of the field to a specified value if the specified value is less than the current value of the field. |
||
| 803 | * |
||
| 804 | * @see Builder::min() |
||
| 805 | * @see http://docs.mongodb.org/manual/reference/operator/update/min/ |
||
| 806 | * @param mixed $value |
||
| 807 | * @return $this |
||
| 808 | */ |
||
| 809 | public function min($value) |
||
| 815 | |||
| 816 | /** |
||
| 817 | * Specify $mod criteria for the current field. |
||
| 818 | * |
||
| 819 | * @see Builder::mod() |
||
| 820 | * @see http://docs.mongodb.org/manual/reference/operator/mod/ |
||
| 821 | * @param float|int $divisor |
||
| 822 | * @param float|int $remainder |
||
| 823 | * @return $this |
||
| 824 | */ |
||
| 825 | public function mod($divisor, $remainder = 0) |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Multiply the current field. |
||
| 832 | * |
||
| 833 | * If the field does not exist, it will be set to 0. |
||
| 834 | * |
||
| 835 | * @see Builder::mul() |
||
| 836 | * @see http://docs.mongodb.org/manual/reference/operator/mul/ |
||
| 837 | * @param float|int $value |
||
| 838 | * @return $this |
||
| 839 | */ |
||
| 840 | public function mul($value) |
||
| 846 | |||
| 847 | /** |
||
| 848 | * Add $near criteria to the expression. |
||
| 849 | * |
||
| 850 | * A GeoJSON point may be provided as the first and only argument for |
||
| 851 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
| 852 | * an array corresponding to the point's JSON representation. |
||
| 853 | * |
||
| 854 | * @see Builder::near() |
||
| 855 | * @see http://docs.mongodb.org/manual/reference/operator/near/ |
||
| 856 | * @param float|array|Point $x |
||
| 857 | * @param float $y |
||
| 858 | * @return $this |
||
| 859 | */ |
||
| 860 | 3 | View Code Duplication | public function near($x, $y = null) |
| 872 | |||
| 873 | /** |
||
| 874 | * Add $nearSphere criteria to the expression. |
||
| 875 | * |
||
| 876 | * A GeoJSON point may be provided as the first and only argument for |
||
| 877 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
| 878 | * an array corresponding to the point's JSON representation. |
||
| 879 | * |
||
| 880 | * @see Builder::nearSphere() |
||
| 881 | * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/ |
||
| 882 | * @param float|array|Point $x |
||
| 883 | * @param float $y |
||
| 884 | * @return $this |
||
| 885 | */ |
||
| 886 | 3 | View Code Duplication | public function nearSphere($x, $y = null) |
| 898 | |||
| 899 | /** |
||
| 900 | * Negates an expression for the current field. |
||
| 901 | * |
||
| 902 | * @see Builder::not() |
||
| 903 | * @see http://docs.mongodb.org/manual/reference/operator/not/ |
||
| 904 | * @param array|Expr $expression |
||
| 905 | * @return $this |
||
| 906 | */ |
||
| 907 | 2 | public function not($expression) |
|
| 911 | |||
| 912 | /** |
||
| 913 | * Specify $ne criteria for the current field. |
||
| 914 | * |
||
| 915 | * @see Builder::notEqual() |
||
| 916 | * @see http://docs.mongodb.org/manual/reference/operator/ne/ |
||
| 917 | * @param mixed $value |
||
| 918 | * @return $this |
||
| 919 | */ |
||
| 920 | 6 | public function notEqual($value) |
|
| 924 | |||
| 925 | /** |
||
| 926 | * Specify $nin criteria for the current field. |
||
| 927 | * |
||
| 928 | * @see Builder::notIn() |
||
| 929 | * @see http://docs.mongodb.org/manual/reference/operator/nin/ |
||
| 930 | * @param array $values |
||
| 931 | * @return $this |
||
| 932 | */ |
||
| 933 | 6 | public function notIn(array $values) |
|
| 937 | |||
| 938 | /** |
||
| 939 | * Defines an operator and value on the expression. |
||
| 940 | * |
||
| 941 | * If there is a current field, the operator will be set on it; otherwise, |
||
| 942 | * the operator is set at the top level of the query. |
||
| 943 | * |
||
| 944 | * @param string $operator |
||
| 945 | * @param mixed $value |
||
| 946 | * @return $this |
||
| 947 | */ |
||
| 948 | 81 | public function operator($operator, $value) |
|
| 959 | |||
| 960 | /** |
||
| 961 | * Remove the first element from the current array field. |
||
| 962 | * |
||
| 963 | * @see Builder::popFirst() |
||
| 964 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
| 965 | * @return $this |
||
| 966 | */ |
||
| 967 | 2 | public function popFirst() |
|
| 973 | |||
| 974 | /** |
||
| 975 | * Remove the last element from the current array field. |
||
| 976 | * |
||
| 977 | * @see Builder::popLast() |
||
| 978 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
| 979 | * @return $this |
||
| 980 | */ |
||
| 981 | 1 | public function popLast() |
|
| 982 | { |
||
| 983 | 1 | $this->requiresCurrentField(); |
|
| 984 | 1 | $this->newObj['$pop'][$this->currentField] = 1; |
|
| 985 | 1 | return $this; |
|
| 986 | } |
||
| 987 | |||
| 988 | /** |
||
| 989 | * Add $position criteria to the expression for a $push operation. |
||
| 990 | * |
||
| 991 | * This is useful in conjunction with {@link Expr::each()} for a |
||
| 992 | * {@link Expr::push()} operation. |
||
| 993 | * |
||
| 994 | * @see http://docs.mongodb.org/manual/reference/operator/update/position/ |
||
| 995 | * @param int $position |
||
| 996 | * @return $this |
||
| 997 | */ |
||
| 998 | 1 | public function position($position) |
|
| 1002 | |||
| 1003 | /** |
||
| 1004 | * Remove all elements matching the given value or expression from the |
||
| 1005 | * current array field. |
||
| 1006 | * |
||
| 1007 | * @see Builder::pull() |
||
| 1008 | * @see http://docs.mongodb.org/manual/reference/operator/pull/ |
||
| 1009 | * @param mixed|Expr $valueOrExpression |
||
| 1010 | * @return $this |
||
| 1011 | */ |
||
| 1012 | 2 | View Code Duplication | public function pull($valueOrExpression) |
| 1022 | |||
| 1023 | /** |
||
| 1024 | * Remove all elements matching any of the given values from the current |
||
| 1025 | * array field. |
||
| 1026 | * |
||
| 1027 | * @see Builder::pullAll() |
||
| 1028 | * @see http://docs.mongodb.org/manual/reference/operator/pullAll/ |
||
| 1029 | * @param array $values |
||
| 1030 | * @return $this |
||
| 1031 | */ |
||
| 1032 | public function pullAll(array $values) |
||
| 1038 | |||
| 1039 | /** |
||
| 1040 | * Append one or more values to the current array field. |
||
| 1041 | * |
||
| 1042 | * If the field does not exist, it will be set to an array containing the |
||
| 1043 | * value(s) in the argument. If the field is not an array, the query |
||
| 1044 | * will yield an error. |
||
| 1045 | * |
||
| 1046 | * Multiple values may be specified by providing an Expr object and using |
||
| 1047 | * {@link Expr::each()}. {@link Expr::slice()} and {@link Expr::sort()} may |
||
| 1048 | * also be used to limit and order array elements, respectively. |
||
| 1049 | * |
||
| 1050 | * @see Builder::push() |
||
| 1051 | * @see http://docs.mongodb.org/manual/reference/operator/push/ |
||
| 1052 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 1053 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
| 1054 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
| 1055 | * @param mixed|Expr $valueOrExpression |
||
| 1056 | * @return $this |
||
| 1057 | */ |
||
| 1058 | 8 | View Code Duplication | public function push($valueOrExpression) |
| 1071 | |||
| 1072 | /** |
||
| 1073 | * Specify $gte and $lt criteria for the current field. |
||
| 1074 | * |
||
| 1075 | * This method is shorthand for specifying $gte criteria on the lower bound |
||
| 1076 | * and $lt criteria on the upper bound. The upper bound is not inclusive. |
||
| 1077 | * |
||
| 1078 | * @see Builder::range() |
||
| 1079 | * @param mixed $start |
||
| 1080 | * @param mixed $end |
||
| 1081 | * @return $this |
||
| 1082 | */ |
||
| 1083 | 2 | public function range($start, $end) |
|
| 1087 | |||
| 1088 | /** |
||
| 1089 | * Checks that the value of the current field is a reference to the supplied document. |
||
| 1090 | * |
||
| 1091 | * @param object $document |
||
| 1092 | * @return Expr |
||
| 1093 | */ |
||
| 1094 | 13 | View Code Duplication | public function references($document) |
| 1135 | |||
| 1136 | /** |
||
| 1137 | * Rename the current field. |
||
| 1138 | * |
||
| 1139 | * @see Builder::rename() |
||
| 1140 | * @see http://docs.mongodb.org/manual/reference/operator/rename/ |
||
| 1141 | * @param string $name |
||
| 1142 | * @return $this |
||
| 1143 | */ |
||
| 1144 | public function rename($name) |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * Set the current field to a value. |
||
| 1153 | * |
||
| 1154 | * This is only relevant for insert, update, or findAndUpdate queries. For |
||
| 1155 | * update and findAndUpdate queries, the $atomic parameter will determine |
||
| 1156 | * whether or not a $set operator is used. |
||
| 1157 | * |
||
| 1158 | * @see Builder::set() |
||
| 1159 | * @see http://docs.mongodb.org/manual/reference/operator/set/ |
||
| 1160 | * @param mixed $value |
||
| 1161 | * @param bool $atomic |
||
| 1162 | * @return $this |
||
| 1163 | */ |
||
| 1164 | 19 | public function set($value, $atomic = true) |
|
| 1187 | |||
| 1188 | /** |
||
| 1189 | * Sets ClassMetadata for document being queried. |
||
| 1190 | * |
||
| 1191 | */ |
||
| 1192 | 393 | public function setClassMetadata(ClassMetadata $class) |
|
| 1196 | |||
| 1197 | /** |
||
| 1198 | * Set the "new object". |
||
| 1199 | * |
||
| 1200 | * @see Builder::setNewObj() |
||
| 1201 | * @param array $newObj |
||
| 1202 | * @return $this |
||
| 1203 | */ |
||
| 1204 | public function setNewObj(array $newObj) |
||
| 1209 | |||
| 1210 | /** |
||
| 1211 | * Set the current field to the value if the document is inserted in an |
||
| 1212 | * upsert operation. |
||
| 1213 | * |
||
| 1214 | * If an update operation with upsert: true results in an insert of a |
||
| 1215 | * document, then $setOnInsert assigns the specified values to the fields in |
||
| 1216 | * the document. If the update operation does not result in an insert, |
||
| 1217 | * $setOnInsert does nothing. |
||
| 1218 | * |
||
| 1219 | * @see Builder::setOnInsert() |
||
| 1220 | * @see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ |
||
| 1221 | * @param mixed $value |
||
| 1222 | * @return $this |
||
| 1223 | */ |
||
| 1224 | 1 | public function setOnInsert($value) |
|
| 1231 | |||
| 1232 | /** |
||
| 1233 | * Set the query criteria. |
||
| 1234 | * |
||
| 1235 | * @see Builder::setQueryArray() |
||
| 1236 | * @param array $query |
||
| 1237 | * @return $this |
||
| 1238 | */ |
||
| 1239 | 18 | public function setQuery(array $query) |
|
| 1244 | |||
| 1245 | /** |
||
| 1246 | * Specify $size criteria for the current field. |
||
| 1247 | * |
||
| 1248 | * @see Builder::size() |
||
| 1249 | * @see http://docs.mongodb.org/manual/reference/operator/size/ |
||
| 1250 | * @param int $size |
||
| 1251 | * @return $this |
||
| 1252 | */ |
||
| 1253 | public function size($size) |
||
| 1257 | |||
| 1258 | /** |
||
| 1259 | * Add $slice criteria to the expression for a $push operation. |
||
| 1260 | * |
||
| 1261 | * This is useful in conjunction with {@link Expr::each()} for a |
||
| 1262 | * {@link Expr::push()} operation. {@link Builder::selectSlice()} should be |
||
| 1263 | * used for specifying $slice for a query projection. |
||
| 1264 | * |
||
| 1265 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
| 1266 | * @param int $slice |
||
| 1267 | * @return $this |
||
| 1268 | */ |
||
| 1269 | 2 | public function slice($slice) |
|
| 1273 | |||
| 1274 | /** |
||
| 1275 | * Add $sort criteria to the expression for a $push operation. |
||
| 1276 | * |
||
| 1277 | * If sorting by multiple fields, the first argument should be an array of |
||
| 1278 | * field name (key) and order (value) pairs. |
||
| 1279 | * |
||
| 1280 | * This is useful in conjunction with {@link Expr::each()} for a |
||
| 1281 | * {@link Expr::push()} operation. {@link Builder::sort()} should be used to |
||
| 1282 | * sort the results of a query. |
||
| 1283 | * |
||
| 1284 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
| 1285 | * @param array|string $fieldName Field name or array of field/order pairs |
||
| 1286 | * @param int|string $order Field order (if one field is specified) |
||
| 1287 | * @return $this |
||
| 1288 | */ |
||
| 1289 | 2 | public function sort($fieldName, $order = null) |
|
| 1297 | |||
| 1298 | /** |
||
| 1299 | * Specify $text criteria for the current query. |
||
| 1300 | * |
||
| 1301 | * The $language option may be set with {@link Expr::language()}. |
||
| 1302 | * |
||
| 1303 | * @see Builder::text() |
||
| 1304 | * @see http://docs.mongodb.org/master/reference/operator/query/text/ |
||
| 1305 | * @param string $search |
||
| 1306 | * @return $this |
||
| 1307 | */ |
||
| 1308 | 6 | public function text($search) |
|
| 1313 | |||
| 1314 | /** |
||
| 1315 | * Specify $type criteria for the current field. |
||
| 1316 | * |
||
| 1317 | * @todo Remove support for string $type argument in 2.0 |
||
| 1318 | * @see Builder::type() |
||
| 1319 | * @see http://docs.mongodb.org/manual/reference/operator/type/ |
||
| 1320 | * @param int $type |
||
| 1321 | * @return $this |
||
| 1322 | */ |
||
| 1323 | 1 | public function type($type) |
|
| 1353 | |||
| 1354 | /** |
||
| 1355 | * Unset the current field. |
||
| 1356 | * |
||
| 1357 | * The field will be removed from the document (not set to null). |
||
| 1358 | * |
||
| 1359 | * @see Builder::unsetField() |
||
| 1360 | * @see http://docs.mongodb.org/manual/reference/operator/unset/ |
||
| 1361 | * @return $this |
||
| 1362 | */ |
||
| 1363 | 3 | public function unsetField() |
|
| 1369 | |||
| 1370 | /** |
||
| 1371 | * Specify a JavaScript expression to use for matching documents. |
||
| 1372 | * |
||
| 1373 | * @see Builder::where() |
||
| 1374 | * @see http://docs.mongodb.org/manual/reference/operator/where/ |
||
| 1375 | * @param string|Javascript $javascript |
||
| 1376 | * @return $this |
||
| 1377 | */ |
||
| 1378 | 3 | public function where($javascript) |
|
| 1383 | |||
| 1384 | /** |
||
| 1385 | * Gets reference mapping for current field from current class or its descendants. |
||
| 1386 | * |
||
| 1387 | * @return array |
||
| 1388 | * @throws MappingException |
||
| 1389 | */ |
||
| 1390 | 19 | private function getReferenceMapping() |
|
| 1418 | |||
| 1419 | /** |
||
| 1420 | * @param int|string $order |
||
| 1421 | * |
||
| 1422 | */ |
||
| 1423 | 2 | private function normalizeSortOrder($order): int |
|
| 1431 | |||
| 1432 | /** |
||
| 1433 | * Ensure that a current field has been set. |
||
| 1434 | * |
||
| 1435 | * @throws \LogicException If a current field has not been set. |
||
| 1436 | */ |
||
| 1437 | 69 | private function requiresCurrentField() |
|
| 1443 | |||
| 1444 | /** |
||
| 1445 | * Wraps equality criteria with an operator. |
||
| 1446 | * |
||
| 1447 | * If equality criteria was previously specified for a field, it cannot be |
||
| 1448 | * merged with other operators without first being wrapped in an operator of |
||
| 1449 | * its own. Ideally, we would wrap it with $eq, but that is only available |
||
| 1450 | * in MongoDB 2.8. Using a single-element $in is backwards compatible. |
||
| 1451 | * |
||
| 1452 | * @see Expr::operator() |
||
| 1453 | */ |
||
| 1454 | 81 | private function wrapEqualityCriteria() |
|
| 1480 | } |
||
| 1481 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.