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 |
||
| 17 | class Expr |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * The query criteria array. |
||
| 21 | * |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | private $query = []; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The "new object" array containing either a full document or a number of |
||
| 28 | * atomic update operators. |
||
| 29 | * |
||
| 30 | * @see docs.mongodb.org/manual/reference/method/db.collection.update/#update-parameter |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | private $newObj = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The current field we are operating on. |
||
| 37 | * |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | private $currentField; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The DocumentManager instance for this query |
||
| 44 | * |
||
| 45 | * @var DocumentManager |
||
| 46 | */ |
||
| 47 | private $dm; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The ClassMetadata instance for the document being queried |
||
| 51 | * |
||
| 52 | * @var ClassMetadata |
||
| 53 | */ |
||
| 54 | private $class; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @param DocumentManager $dm |
||
| 58 | */ |
||
| 59 | 392 | public function __construct(DocumentManager $dm) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Add one or more $and clauses to the current query. |
||
| 66 | * |
||
| 67 | * @see Builder::addAnd() |
||
| 68 | * @see http://docs.mongodb.org/manual/reference/operator/and/ |
||
| 69 | * @param array|Expr $expression |
||
| 70 | * @return $this |
||
| 71 | */ |
||
| 72 | 3 | View Code Duplication | public function addAnd($expression /*, $expression2, ... */) |
| 90 | |||
| 91 | /** |
||
| 92 | * Add one or more $nor clauses to the current query. |
||
| 93 | * |
||
| 94 | * @see Builder::addNor() |
||
| 95 | * @see http://docs.mongodb.org/manual/reference/operator/nor/ |
||
| 96 | * @param array|Expr $expression |
||
| 97 | * @return $this |
||
| 98 | */ |
||
| 99 | 1 | View Code Duplication | public function addNor($expression /* , $expression2, ... */) |
| 112 | |||
| 113 | /** |
||
| 114 | * Add one or more $or clauses to the current query. |
||
| 115 | * |
||
| 116 | * @see Builder::addOr() |
||
| 117 | * @see http://docs.mongodb.org/manual/reference/operator/or/ |
||
| 118 | * @param array|Expr $expression |
||
| 119 | * @return $this |
||
| 120 | */ |
||
| 121 | 5 | View Code Duplication | public function addOr($expression /* , $expression2, ... */) |
| 134 | |||
| 135 | /** |
||
| 136 | * Append one or more values to the current array field only if they do not |
||
| 137 | * already exist in the array. |
||
| 138 | * |
||
| 139 | * If the field does not exist, it will be set to an array containing the |
||
| 140 | * unique value(s) in the argument. If the field is not an array, the query |
||
| 141 | * will yield an error. |
||
| 142 | * |
||
| 143 | * Multiple values may be specified by provided an Expr object and using |
||
| 144 | * {@link Expr::each()}. |
||
| 145 | * |
||
| 146 | * @see Builder::addToSet() |
||
| 147 | * @see http://docs.mongodb.org/manual/reference/operator/addToSet/ |
||
| 148 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 149 | * @param mixed|Expr $valueOrExpression |
||
| 150 | * @return $this |
||
| 151 | */ |
||
| 152 | 5 | View Code Duplication | public function addToSet($valueOrExpression) |
| 162 | |||
| 163 | /** |
||
| 164 | * Specify $all criteria for the current field. |
||
| 165 | * |
||
| 166 | * @see Builder::all() |
||
| 167 | * @see http://docs.mongodb.org/manual/reference/operator/all/ |
||
| 168 | * @param array $values |
||
| 169 | * @return $this |
||
| 170 | */ |
||
| 171 | 2 | public function all(array $values) |
|
| 175 | |||
| 176 | /** |
||
| 177 | * Apply a bitwise operation on the current field |
||
| 178 | * |
||
| 179 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 180 | * @param string $operator |
||
| 181 | * @param int $value |
||
| 182 | * @return $this |
||
| 183 | */ |
||
| 184 | 3 | protected function bit($operator, $value) |
|
| 190 | |||
| 191 | /** |
||
| 192 | * Apply a bitwise and operation on the current field. |
||
| 193 | * |
||
| 194 | * @see Builder::bitAnd() |
||
| 195 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 196 | * @param int $value |
||
| 197 | * @return $this |
||
| 198 | */ |
||
| 199 | 1 | public function bitAnd($value) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Apply a bitwise or operation on the current field. |
||
| 206 | * |
||
| 207 | * @see Builder::bitOr() |
||
| 208 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 209 | * @param int $value |
||
| 210 | * @return $this |
||
| 211 | */ |
||
| 212 | 1 | public function bitOr($value) |
|
| 216 | |||
| 217 | /** |
||
| 218 | * Matches documents where all of the bit positions given by the query are |
||
| 219 | * clear. |
||
| 220 | * |
||
| 221 | * @see Builder::bitsAllClear() |
||
| 222 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllClear/ |
||
| 223 | * @param int|array|\MongoBinData $value |
||
| 224 | * @return $this |
||
| 225 | */ |
||
| 226 | public function bitsAllClear($value) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * Matches documents where all of the bit positions given by the query are |
||
| 234 | * set. |
||
| 235 | * |
||
| 236 | * @see Builder::bitsAllSet() |
||
| 237 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAllSet/ |
||
| 238 | * @param int|array|\MongoBinData $value |
||
| 239 | * @return $this |
||
| 240 | */ |
||
| 241 | public function bitsAllSet($value) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * Matches documents where any of the bit positions given by the query are |
||
| 249 | * clear. |
||
| 250 | * |
||
| 251 | * @see Builder::bitsAnyClear() |
||
| 252 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnyClear/ |
||
| 253 | * @param int|array|\MongoBinData $value |
||
| 254 | * @return $this |
||
| 255 | */ |
||
| 256 | public function bitsAnyClear($value) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Matches documents where any of the bit positions given by the query are |
||
| 264 | * set. |
||
| 265 | * |
||
| 266 | * @see Builder::bitsAnySet() |
||
| 267 | * @see https://docs.mongodb.org/manual/reference/operator/query/bitsAnySet/ |
||
| 268 | * @param int|array|\MongoBinData $value |
||
| 269 | * @return $this |
||
| 270 | */ |
||
| 271 | public function bitsAnySet($value) |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Apply a bitwise xor operation on the current field. |
||
| 279 | * |
||
| 280 | * @see Builder::bitXor() |
||
| 281 | * @see http://docs.mongodb.org/manual/reference/operator/update/bit/ |
||
| 282 | * @param int $value |
||
| 283 | * @return $this |
||
| 284 | */ |
||
| 285 | 1 | public function bitXor($value) |
|
| 289 | |||
| 290 | /** |
||
| 291 | * A boolean flag to enable or disable case sensitive search for $text |
||
| 292 | * criteria. |
||
| 293 | * |
||
| 294 | * This method must be called after text(). |
||
| 295 | * |
||
| 296 | * @see Builder::caseSensitive() |
||
| 297 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 298 | * @param bool $caseSensitive |
||
| 299 | * @return $this |
||
| 300 | * @throws \BadMethodCallException if the query does not already have $text criteria |
||
| 301 | * |
||
| 302 | * @since 1.3 |
||
| 303 | */ |
||
| 304 | 3 | View Code Duplication | public function caseSensitive($caseSensitive) |
| 319 | |||
| 320 | /** |
||
| 321 | * Associates a comment to any expression taking a query predicate. |
||
| 322 | * |
||
| 323 | * @see Builder::comment() |
||
| 324 | * @see http://docs.mongodb.org/manual/reference/operator/query/comment/ |
||
| 325 | * @param string $comment |
||
| 326 | * @return $this |
||
| 327 | */ |
||
| 328 | public function comment($comment) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Sets the value of the current field to the current date, either as a date or a timestamp. |
||
| 336 | * |
||
| 337 | * @see Builder::currentDate() |
||
| 338 | * @see http://docs.mongodb.org/manual/reference/operator/update/currentDate/ |
||
| 339 | * @param string $type |
||
| 340 | * @return $this |
||
| 341 | * @throws \InvalidArgumentException if an invalid type is given |
||
| 342 | */ |
||
| 343 | 3 | public function currentDate($type = 'date') |
|
| 353 | |||
| 354 | /** |
||
| 355 | * A boolean flag to enable or disable diacritic sensitive search for $text |
||
| 356 | * criteria. |
||
| 357 | * |
||
| 358 | * This method must be called after text(). |
||
| 359 | * |
||
| 360 | * @see Builder::diacriticSensitive() |
||
| 361 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 362 | * @param bool $diacriticSensitive |
||
| 363 | * @return $this |
||
| 364 | * @throws \BadMethodCallException if the query does not already have $text criteria |
||
| 365 | * |
||
| 366 | * @since 1.3 |
||
| 367 | */ |
||
| 368 | 3 | View Code Duplication | public function diacriticSensitive($diacriticSensitive) |
| 383 | |||
| 384 | /** |
||
| 385 | * Add $each criteria to the expression for a $push operation. |
||
| 386 | * |
||
| 387 | * @see Expr::push() |
||
| 388 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 389 | * @param array $values |
||
| 390 | * @return $this |
||
| 391 | */ |
||
| 392 | 4 | public function each(array $values) |
|
| 396 | |||
| 397 | /** |
||
| 398 | * Specify $elemMatch criteria for the current field. |
||
| 399 | * |
||
| 400 | * @see Builder::elemMatch() |
||
| 401 | * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/ |
||
| 402 | * @param array|Expr $expression |
||
| 403 | * @return $this |
||
| 404 | */ |
||
| 405 | 4 | public function elemMatch($expression) |
|
| 409 | |||
| 410 | /** |
||
| 411 | * Specify an equality match for the current field. |
||
| 412 | * |
||
| 413 | * @see Builder::equals() |
||
| 414 | * @param mixed $value |
||
| 415 | * @return $this |
||
| 416 | */ |
||
| 417 | 100 | public function equals($value) |
|
| 426 | |||
| 427 | /** |
||
| 428 | * Specify $exists criteria for the current field. |
||
| 429 | * |
||
| 430 | * @see Builder::exists() |
||
| 431 | * @see http://docs.mongodb.org/manual/reference/operator/exists/ |
||
| 432 | * @param boolean $bool |
||
| 433 | * @return $this |
||
| 434 | */ |
||
| 435 | 5 | public function exists($bool) |
|
| 439 | |||
| 440 | /** |
||
| 441 | * Set the current field for building the expression. |
||
| 442 | * |
||
| 443 | * @see Builder::field() |
||
| 444 | * @param string $field |
||
| 445 | * @return $this |
||
| 446 | */ |
||
| 447 | 191 | public function field($field) |
|
| 452 | |||
| 453 | /** |
||
| 454 | * Add $geoIntersects criteria with a GeoJSON geometry to the expression. |
||
| 455 | * |
||
| 456 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
| 457 | * geometry's JSON representation. |
||
| 458 | * |
||
| 459 | * @see Builder::geoIntersects() |
||
| 460 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
| 461 | * @param array|Geometry $geometry |
||
| 462 | * @return $this |
||
| 463 | */ |
||
| 464 | 2 | View Code Duplication | public function geoIntersects($geometry) |
| 472 | |||
| 473 | /** |
||
| 474 | * Add $geoWithin criteria with a GeoJSON geometry to the expression. |
||
| 475 | * |
||
| 476 | * The geometry parameter GeoJSON object or an array corresponding to the |
||
| 477 | * geometry's JSON representation. |
||
| 478 | * |
||
| 479 | * @see Builder::geoWithin() |
||
| 480 | * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/ |
||
| 481 | * @param array|Geometry $geometry |
||
| 482 | * @return $this |
||
| 483 | */ |
||
| 484 | 2 | View Code Duplication | public function geoWithin($geometry) |
| 492 | |||
| 493 | /** |
||
| 494 | * Add $geoWithin criteria with a $box shape to the expression. |
||
| 495 | * |
||
| 496 | * A rectangular polygon will be constructed from a pair of coordinates |
||
| 497 | * corresponding to the bottom left and top right corners. |
||
| 498 | * |
||
| 499 | * Note: the $box operator only supports legacy coordinate pairs and 2d |
||
| 500 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 501 | * |
||
| 502 | * @see Builder::geoWithinBox() |
||
| 503 | * @see http://docs.mongodb.org/manual/reference/operator/box/ |
||
| 504 | * @param float $x1 |
||
| 505 | * @param float $y1 |
||
| 506 | * @param float $x2 |
||
| 507 | * @param float $y2 |
||
| 508 | * @return $this |
||
| 509 | */ |
||
| 510 | 1 | public function geoWithinBox($x1, $y1, $x2, $y2) |
|
| 516 | |||
| 517 | /** |
||
| 518 | * Add $geoWithin criteria with a $center shape to the expression. |
||
| 519 | * |
||
| 520 | * Note: the $center operator only supports legacy coordinate pairs and 2d |
||
| 521 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 522 | * |
||
| 523 | * @see Builider::geoWithinCenter() |
||
| 524 | * @see http://docs.mongodb.org/manual/reference/operator/center/ |
||
| 525 | * @param float $x |
||
| 526 | * @param float $y |
||
| 527 | * @param float $radius |
||
| 528 | * @return $this |
||
| 529 | */ |
||
| 530 | 1 | public function geoWithinCenter($x, $y, $radius) |
|
| 536 | |||
| 537 | /** |
||
| 538 | * Add $geoWithin criteria with a $centerSphere shape to the expression. |
||
| 539 | * |
||
| 540 | * Note: the $centerSphere operator supports both 2d and 2dsphere indexes. |
||
| 541 | * |
||
| 542 | * @see Builder::geoWithinCenterSphere() |
||
| 543 | * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/ |
||
| 544 | * @param float $x |
||
| 545 | * @param float $y |
||
| 546 | * @param float $radius |
||
| 547 | * @return $this |
||
| 548 | */ |
||
| 549 | 1 | public function geoWithinCenterSphere($x, $y, $radius) |
|
| 555 | |||
| 556 | /** |
||
| 557 | * Add $geoWithin criteria with a $polygon shape to the expression. |
||
| 558 | * |
||
| 559 | * Point coordinates are in x, y order (easting, northing for projected |
||
| 560 | * coordinates, longitude, latitude for geographic coordinates). |
||
| 561 | * |
||
| 562 | * The last point coordinate is implicitly connected with the first. |
||
| 563 | * |
||
| 564 | * Note: the $polygon operator only supports legacy coordinate pairs and 2d |
||
| 565 | * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes. |
||
| 566 | * |
||
| 567 | * @see Builder::geoWithinPolygon() |
||
| 568 | * @see http://docs.mongodb.org/manual/reference/operator/polygon/ |
||
| 569 | * @param array $point,... Three or more point coordinate tuples |
||
| 570 | * @return $this |
||
| 571 | * @throws \InvalidArgumentException if less than three points are given |
||
| 572 | */ |
||
| 573 | 2 | public function geoWithinPolygon(/* array($x1, $y1), ... */) |
|
| 583 | |||
| 584 | /** |
||
| 585 | * Return the current field. |
||
| 586 | * |
||
| 587 | * @return string |
||
| 588 | */ |
||
| 589 | 2 | public function getCurrentField() |
|
| 593 | |||
| 594 | /** |
||
| 595 | * Gets prepared newObj part of expression. |
||
| 596 | * |
||
| 597 | * @return array |
||
| 598 | */ |
||
| 599 | 174 | public function getNewObj() |
|
| 605 | |||
| 606 | /** |
||
| 607 | * Gets prepared query part of expression. |
||
| 608 | * |
||
| 609 | * @return array |
||
| 610 | */ |
||
| 611 | 250 | public function getQuery() |
|
| 617 | |||
| 618 | /** |
||
| 619 | * Specify $gt criteria for the current field. |
||
| 620 | * |
||
| 621 | * @see Builder::gt() |
||
| 622 | * @see http://docs.mongodb.org/manual/reference/operator/gt/ |
||
| 623 | * @param mixed $value |
||
| 624 | * @return $this |
||
| 625 | */ |
||
| 626 | 2 | public function gt($value) |
|
| 630 | |||
| 631 | /** |
||
| 632 | * Specify $gte criteria for the current field. |
||
| 633 | * |
||
| 634 | * @see Builder::gte() |
||
| 635 | * @see http://docs.mongodb.org/manual/reference/operator/gte/ |
||
| 636 | * @param mixed $value |
||
| 637 | * @return $this |
||
| 638 | */ |
||
| 639 | 2 | public function gte($value) |
|
| 643 | |||
| 644 | /** |
||
| 645 | * Specify $in criteria for the current field. |
||
| 646 | * |
||
| 647 | * @see Builder::in() |
||
| 648 | * @see http://docs.mongodb.org/manual/reference/operator/in/ |
||
| 649 | * @param array $values |
||
| 650 | * @return $this |
||
| 651 | */ |
||
| 652 | 31 | public function in(array $values) |
|
| 656 | |||
| 657 | /** |
||
| 658 | * Increment the current field. |
||
| 659 | * |
||
| 660 | * If the field does not exist, it will be set to this value. |
||
| 661 | * |
||
| 662 | * @see Builder::inc() |
||
| 663 | * @see http://docs.mongodb.org/manual/reference/operator/inc/ |
||
| 664 | * @param float|integer $value |
||
| 665 | * @return $this |
||
| 666 | */ |
||
| 667 | 5 | public function inc($value) |
|
| 673 | |||
| 674 | /** |
||
| 675 | * Checks that the current field includes a reference to the supplied document. |
||
| 676 | * |
||
| 677 | * @param object $document |
||
| 678 | * @return Expr |
||
| 679 | */ |
||
| 680 | 6 | View Code Duplication | public function includesReferenceTo($document) |
| 720 | |||
| 721 | /** |
||
| 722 | * Set the $language option for $text criteria. |
||
| 723 | * |
||
| 724 | * This method must be called after text(). |
||
| 725 | * |
||
| 726 | * @see Builder::language() |
||
| 727 | * @see http://docs.mongodb.org/manual/reference/operator/text/ |
||
| 728 | * @param string $language |
||
| 729 | * @return $this |
||
| 730 | * @throws \BadMethodCallException if the query does not already have $text criteria |
||
| 731 | */ |
||
| 732 | 2 | public function language($language) |
|
| 742 | |||
| 743 | /** |
||
| 744 | * Specify $lt criteria for the current field. |
||
| 745 | * |
||
| 746 | * @see Builder::lte() |
||
| 747 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
| 748 | * @param mixed $value |
||
| 749 | * @return $this |
||
| 750 | */ |
||
| 751 | 4 | public function lt($value) |
|
| 755 | |||
| 756 | /** |
||
| 757 | * Specify $lte criteria for the current field. |
||
| 758 | * |
||
| 759 | * @see Builder::lte() |
||
| 760 | * @see http://docs.mongodb.org/manual/reference/operator/lte/ |
||
| 761 | * @param mixed $value |
||
| 762 | * @return $this |
||
| 763 | */ |
||
| 764 | 2 | public function lte($value) |
|
| 768 | |||
| 769 | /** |
||
| 770 | * Updates the value of the field to a specified value if the specified value is greater than the current value of the field. |
||
| 771 | * |
||
| 772 | * @see Builder::max() |
||
| 773 | * @see http://docs.mongodb.org/manual/reference/operator/update/max/ |
||
| 774 | * @param mixed $value |
||
| 775 | * @return $this |
||
| 776 | */ |
||
| 777 | public function max($value) |
||
| 783 | |||
| 784 | /** |
||
| 785 | * Updates the value of the field to a specified value if the specified value is less than the current value of the field. |
||
| 786 | * |
||
| 787 | * @see Builder::min() |
||
| 788 | * @see http://docs.mongodb.org/manual/reference/operator/update/min/ |
||
| 789 | * @param mixed $value |
||
| 790 | * @return $this |
||
| 791 | */ |
||
| 792 | public function min($value) |
||
| 798 | |||
| 799 | /** |
||
| 800 | * Specify $mod criteria for the current field. |
||
| 801 | * |
||
| 802 | * @see Builder::mod() |
||
| 803 | * @see http://docs.mongodb.org/manual/reference/operator/mod/ |
||
| 804 | * @param float|integer $divisor |
||
| 805 | * @param float|integer $remainder |
||
| 806 | * @return $this |
||
| 807 | */ |
||
| 808 | public function mod($divisor, $remainder = 0) |
||
| 812 | |||
| 813 | /** |
||
| 814 | * Multiply the current field. |
||
| 815 | * |
||
| 816 | * If the field does not exist, it will be set to 0. |
||
| 817 | * |
||
| 818 | * @see Builder::mul() |
||
| 819 | * @see http://docs.mongodb.org/manual/reference/operator/mul/ |
||
| 820 | * @param float|integer $value |
||
| 821 | * @return $this |
||
| 822 | */ |
||
| 823 | public function mul($value) |
||
| 829 | |||
| 830 | /** |
||
| 831 | * Add $near criteria to the expression. |
||
| 832 | * |
||
| 833 | * A GeoJSON point may be provided as the first and only argument for |
||
| 834 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
| 835 | * an array corresponding to the point's JSON representation. |
||
| 836 | * |
||
| 837 | * @see Builder::near() |
||
| 838 | * @see http://docs.mongodb.org/manual/reference/operator/near/ |
||
| 839 | * @param float|array|Point $x |
||
| 840 | * @param float $y |
||
| 841 | * @return $this |
||
| 842 | */ |
||
| 843 | 3 | View Code Duplication | public function near($x, $y = null) |
| 855 | |||
| 856 | /** |
||
| 857 | * Add $nearSphere criteria to the expression. |
||
| 858 | * |
||
| 859 | * A GeoJSON point may be provided as the first and only argument for |
||
| 860 | * 2dsphere queries. This single parameter may be a GeoJSON point object or |
||
| 861 | * an array corresponding to the point's JSON representation. |
||
| 862 | * |
||
| 863 | * @see Builder::nearSphere() |
||
| 864 | * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/ |
||
| 865 | * @param float|array|Point $x |
||
| 866 | * @param float $y |
||
| 867 | * @return $this |
||
| 868 | */ |
||
| 869 | 3 | View Code Duplication | public function nearSphere($x, $y = null) |
| 881 | |||
| 882 | /** |
||
| 883 | * Negates an expression for the current field. |
||
| 884 | * |
||
| 885 | * @see Builder::not() |
||
| 886 | * @see http://docs.mongodb.org/manual/reference/operator/not/ |
||
| 887 | * @param array|Expr $expression |
||
| 888 | * @return $this |
||
| 889 | */ |
||
| 890 | 2 | public function not($expression) |
|
| 894 | |||
| 895 | /** |
||
| 896 | * Specify $ne criteria for the current field. |
||
| 897 | * |
||
| 898 | * @see Builder::notEqual() |
||
| 899 | * @see http://docs.mongodb.org/manual/reference/operator/ne/ |
||
| 900 | * @param mixed $value |
||
| 901 | * @return $this |
||
| 902 | */ |
||
| 903 | 6 | public function notEqual($value) |
|
| 907 | |||
| 908 | /** |
||
| 909 | * Specify $nin criteria for the current field. |
||
| 910 | * |
||
| 911 | * @see Builder::notIn() |
||
| 912 | * @see http://docs.mongodb.org/manual/reference/operator/nin/ |
||
| 913 | * @param array $values |
||
| 914 | * @return $this |
||
| 915 | */ |
||
| 916 | 6 | public function notIn(array $values) |
|
| 920 | |||
| 921 | /** |
||
| 922 | * Defines an operator and value on the expression. |
||
| 923 | * |
||
| 924 | * If there is a current field, the operator will be set on it; otherwise, |
||
| 925 | * the operator is set at the top level of the query. |
||
| 926 | * |
||
| 927 | * @param string $operator |
||
| 928 | * @param mixed $value |
||
| 929 | * @return $this |
||
| 930 | */ |
||
| 931 | 81 | public function operator($operator, $value) |
|
| 942 | |||
| 943 | /** |
||
| 944 | * Remove the first element from the current array field. |
||
| 945 | * |
||
| 946 | * @see Builder::popFirst() |
||
| 947 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
| 948 | * @return $this |
||
| 949 | */ |
||
| 950 | 1 | public function popFirst() |
|
| 956 | |||
| 957 | /** |
||
| 958 | * Remove the last element from the current array field. |
||
| 959 | * |
||
| 960 | * @see Builder::popLast() |
||
| 961 | * @see http://docs.mongodb.org/manual/reference/operator/pop/ |
||
| 962 | * @return $this |
||
| 963 | */ |
||
| 964 | public function popLast() |
||
| 970 | |||
| 971 | /** |
||
| 972 | * Add $position criteria to the expression for a $push operation. |
||
| 973 | * |
||
| 974 | * This is useful in conjunction with {@link Expr::each()} for a |
||
| 975 | * {@link Expr::push()} operation. |
||
| 976 | * |
||
| 977 | * @see http://docs.mongodb.org/manual/reference/operator/update/position/ |
||
| 978 | * @param integer $position |
||
| 979 | * @return $this |
||
| 980 | */ |
||
| 981 | 1 | public function position($position) |
|
| 985 | |||
| 986 | /** |
||
| 987 | * Remove all elements matching the given value or expression from the |
||
| 988 | * current array field. |
||
| 989 | * |
||
| 990 | * @see Builder::pull() |
||
| 991 | * @see http://docs.mongodb.org/manual/reference/operator/pull/ |
||
| 992 | * @param mixed|Expr $valueOrExpression |
||
| 993 | * @return $this |
||
| 994 | */ |
||
| 995 | 2 | View Code Duplication | public function pull($valueOrExpression) |
| 1005 | |||
| 1006 | /** |
||
| 1007 | * Remove all elements matching any of the given values from the current |
||
| 1008 | * array field. |
||
| 1009 | * |
||
| 1010 | * @see Builder::pullAll() |
||
| 1011 | * @see http://docs.mongodb.org/manual/reference/operator/pullAll/ |
||
| 1012 | * @param array $values |
||
| 1013 | * @return $this |
||
| 1014 | */ |
||
| 1015 | public function pullAll(array $values) |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * Append one or more values to the current array field. |
||
| 1024 | * |
||
| 1025 | * If the field does not exist, it will be set to an array containing the |
||
| 1026 | * value(s) in the argument. If the field is not an array, the query |
||
| 1027 | * will yield an error. |
||
| 1028 | * |
||
| 1029 | * Multiple values may be specified by providing an Expr object and using |
||
| 1030 | * {@link Expr::each()}. {@link Expr::slice()} and {@link Expr::sort()} may |
||
| 1031 | * also be used to limit and order array elements, respectively. |
||
| 1032 | * |
||
| 1033 | * @see Builder::push() |
||
| 1034 | * @see http://docs.mongodb.org/manual/reference/operator/push/ |
||
| 1035 | * @see http://docs.mongodb.org/manual/reference/operator/each/ |
||
| 1036 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
| 1037 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
| 1038 | * @param mixed|Expr $valueOrExpression |
||
| 1039 | * @return $this |
||
| 1040 | */ |
||
| 1041 | 8 | View Code Duplication | public function push($valueOrExpression) |
| 1054 | |||
| 1055 | /** |
||
| 1056 | * Specify $gte and $lt criteria for the current field. |
||
| 1057 | * |
||
| 1058 | * This method is shorthand for specifying $gte criteria on the lower bound |
||
| 1059 | * and $lt criteria on the upper bound. The upper bound is not inclusive. |
||
| 1060 | * |
||
| 1061 | * @see Builder::range() |
||
| 1062 | * @param mixed $start |
||
| 1063 | * @param mixed $end |
||
| 1064 | * @return $this |
||
| 1065 | */ |
||
| 1066 | 2 | public function range($start, $end) |
|
| 1070 | |||
| 1071 | /** |
||
| 1072 | * Checks that the value of the current field is a reference to the supplied document. |
||
| 1073 | * |
||
| 1074 | * @param object $document |
||
| 1075 | * @return Expr |
||
| 1076 | */ |
||
| 1077 | 13 | View Code Duplication | public function references($document) |
| 1117 | |||
| 1118 | /** |
||
| 1119 | * Rename the current field. |
||
| 1120 | * |
||
| 1121 | * @see Builder::rename() |
||
| 1122 | * @see http://docs.mongodb.org/manual/reference/operator/rename/ |
||
| 1123 | * @param string $name |
||
| 1124 | * @return $this |
||
| 1125 | */ |
||
| 1126 | public function rename($name) |
||
| 1132 | |||
| 1133 | /** |
||
| 1134 | * Set the current field to a value. |
||
| 1135 | * |
||
| 1136 | * This is only relevant for insert, update, or findAndUpdate queries. For |
||
| 1137 | * update and findAndUpdate queries, the $atomic parameter will determine |
||
| 1138 | * whether or not a $set operator is used. |
||
| 1139 | * |
||
| 1140 | * @see Builder::set() |
||
| 1141 | * @see http://docs.mongodb.org/manual/reference/operator/set/ |
||
| 1142 | * @param mixed $value |
||
| 1143 | * @param boolean $atomic |
||
| 1144 | * @return $this |
||
| 1145 | */ |
||
| 1146 | 19 | public function set($value, $atomic = true) |
|
| 1169 | |||
| 1170 | /** |
||
| 1171 | * Sets ClassMetadata for document being queried. |
||
| 1172 | * |
||
| 1173 | * @param ClassMetadata $class |
||
| 1174 | */ |
||
| 1175 | 390 | public function setClassMetadata(ClassMetadata $class) |
|
| 1179 | |||
| 1180 | /** |
||
| 1181 | * Set the "new object". |
||
| 1182 | * |
||
| 1183 | * @see Builder::setNewObj() |
||
| 1184 | * @param array $newObj |
||
| 1185 | * @return $this |
||
| 1186 | */ |
||
| 1187 | public function setNewObj(array $newObj) |
||
| 1192 | |||
| 1193 | /** |
||
| 1194 | * Set the current field to the value if the document is inserted in an |
||
| 1195 | * upsert operation. |
||
| 1196 | * |
||
| 1197 | * If an update operation with upsert: true results in an insert of a |
||
| 1198 | * document, then $setOnInsert assigns the specified values to the fields in |
||
| 1199 | * the document. If the update operation does not result in an insert, |
||
| 1200 | * $setOnInsert does nothing. |
||
| 1201 | * |
||
| 1202 | * @see Builder::setOnInsert() |
||
| 1203 | * @see https://docs.mongodb.org/manual/reference/operator/update/setOnInsert/ |
||
| 1204 | * @param mixed $value |
||
| 1205 | * @return $this |
||
| 1206 | */ |
||
| 1207 | 1 | public function setOnInsert($value) |
|
| 1214 | |||
| 1215 | /** |
||
| 1216 | * Set the query criteria. |
||
| 1217 | * |
||
| 1218 | * @see Builder::setQueryArray() |
||
| 1219 | * @param array $query |
||
| 1220 | * @return $this |
||
| 1221 | */ |
||
| 1222 | 18 | public function setQuery(array $query) |
|
| 1227 | |||
| 1228 | /** |
||
| 1229 | * Specify $size criteria for the current field. |
||
| 1230 | * |
||
| 1231 | * @see Builder::size() |
||
| 1232 | * @see http://docs.mongodb.org/manual/reference/operator/size/ |
||
| 1233 | * @param integer $size |
||
| 1234 | * @return $this |
||
| 1235 | */ |
||
| 1236 | public function size($size) |
||
| 1240 | |||
| 1241 | /** |
||
| 1242 | * Add $slice criteria to the expression for a $push operation. |
||
| 1243 | * |
||
| 1244 | * This is useful in conjunction with {@link Expr::each()} for a |
||
| 1245 | * {@link Expr::push()} operation. {@link Builder::selectSlice()} should be |
||
| 1246 | * used for specifying $slice for a query projection. |
||
| 1247 | * |
||
| 1248 | * @see http://docs.mongodb.org/manual/reference/operator/slice/ |
||
| 1249 | * @param integer $slice |
||
| 1250 | * @return $this |
||
| 1251 | */ |
||
| 1252 | 2 | public function slice($slice) |
|
| 1256 | |||
| 1257 | /** |
||
| 1258 | * Add $sort criteria to the expression for a $push operation. |
||
| 1259 | * |
||
| 1260 | * If sorting by multiple fields, the first argument should be an array of |
||
| 1261 | * field name (key) and order (value) pairs. |
||
| 1262 | * |
||
| 1263 | * This is useful in conjunction with {@link Expr::each()} for a |
||
| 1264 | * {@link Expr::push()} operation. {@link Builder::sort()} should be used to |
||
| 1265 | * sort the results of a query. |
||
| 1266 | * |
||
| 1267 | * @see http://docs.mongodb.org/manual/reference/operator/sort/ |
||
| 1268 | * @param array|string $fieldName Field name or array of field/order pairs |
||
| 1269 | * @param int|string $order Field order (if one field is specified) |
||
| 1270 | * @return $this |
||
| 1271 | */ |
||
| 1272 | 2 | public function sort($fieldName, $order = null) |
|
| 1278 | |||
| 1279 | /** |
||
| 1280 | * Specify $text criteria for the current query. |
||
| 1281 | * |
||
| 1282 | * The $language option may be set with {@link Expr::language()}. |
||
| 1283 | * |
||
| 1284 | * @see Builder::text() |
||
| 1285 | * @see http://docs.mongodb.org/master/reference/operator/query/text/ |
||
| 1286 | * @param string $search |
||
| 1287 | * @return $this |
||
| 1288 | */ |
||
| 1289 | 6 | public function text($search) |
|
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Specify $type criteria for the current field. |
||
| 1297 | * |
||
| 1298 | * @todo Remove support for string $type argument in 2.0 |
||
| 1299 | * @see Builder::type() |
||
| 1300 | * @see http://docs.mongodb.org/manual/reference/operator/type/ |
||
| 1301 | * @param integer $type |
||
| 1302 | * @return $this |
||
| 1303 | */ |
||
| 1304 | 1 | public function type($type) |
|
| 1334 | |||
| 1335 | /** |
||
| 1336 | * Unset the current field. |
||
| 1337 | * |
||
| 1338 | * The field will be removed from the document (not set to null). |
||
| 1339 | * |
||
| 1340 | * @see Builder::unsetField() |
||
| 1341 | * @see http://docs.mongodb.org/manual/reference/operator/unset/ |
||
| 1342 | * @return $this |
||
| 1343 | */ |
||
| 1344 | 3 | public function unsetField() |
|
| 1350 | |||
| 1351 | /** |
||
| 1352 | * Specify a JavaScript expression to use for matching documents. |
||
| 1353 | * |
||
| 1354 | * @see Builder::where() |
||
| 1355 | * @see http://docs.mongodb.org/manual/reference/operator/where/ |
||
| 1356 | * @param string|\MongoCode $javascript |
||
| 1357 | * @return $this |
||
| 1358 | */ |
||
| 1359 | 3 | public function where($javascript) |
|
| 1364 | |||
| 1365 | /** |
||
| 1366 | * Gets reference mapping for current field from current class or its descendants. |
||
| 1367 | * |
||
| 1368 | * @return array |
||
| 1369 | * @throws MappingException |
||
| 1370 | */ |
||
| 1371 | 19 | private function getReferenceMapping() |
|
| 1397 | |||
| 1398 | /** |
||
| 1399 | * @param int|string $order |
||
| 1400 | * |
||
| 1401 | * @return int |
||
| 1402 | */ |
||
| 1403 | 2 | private function normalizeSortOrder($order): int |
|
| 1411 | |||
| 1412 | /** |
||
| 1413 | * Ensure that a current field has been set. |
||
| 1414 | * |
||
| 1415 | * @throws \LogicException if a current field has not been set |
||
| 1416 | */ |
||
| 1417 | 67 | private function requiresCurrentField() |
|
| 1423 | |||
| 1424 | /** |
||
| 1425 | * Wraps equality criteria with an operator. |
||
| 1426 | * |
||
| 1427 | * If equality criteria was previously specified for a field, it cannot be |
||
| 1428 | * merged with other operators without first being wrapped in an operator of |
||
| 1429 | * its own. Ideally, we would wrap it with $eq, but that is only available |
||
| 1430 | * in MongoDB 2.8. Using a single-element $in is backwards compatible. |
||
| 1431 | * |
||
| 1432 | * @see Expr::operator() |
||
| 1433 | */ |
||
| 1434 | 81 | private function wrapEqualityCriteria() |
|
| 1460 | } |
||
| 1461 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.