Completed
Push — master ( 11f27c...4713a5 )
by Andreas
08:33
created

Match   B

Complexity

Total Complexity 39

Size/Duplication

Total Lines 602
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 78.9%

Importance

Changes 0
Metric Value
wmc 39
lcom 2
cbo 3
dl 0
loc 602
ccs 86
cts 109
cp 0.789
rs 8.2808
c 0
b 0
f 0

37 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __clone() 0 4 1
A addAnd() 0 6 1
A addNor() 0 6 1
A addOr() 0 6 1
A all() 0 6 1
A debug() 0 4 2
A elemMatch() 0 6 1
A equals() 0 6 1
A exists() 0 6 1
A expr() 0 4 1
A field() 0 6 1
A geoIntersects() 0 6 1
A geoWithin() 0 6 1
A geoWithinBox() 0 6 1
A geoWithinCenter() 0 6 1
A geoWithinCenterSphere() 0 6 1
A geoWithinPolygon() 0 6 1
A getExpression() 0 6 2
A gt() 0 6 1
A gte() 0 6 1
A in() 0 6 1
A includesReferenceTo() 0 6 1
A language() 0 6 1
A lt() 0 6 1
A lte() 0 6 1
A maxDistance() 0 6 1
A minDistance() 0 6 1
A mod() 0 6 1
A not() 0 6 1
A notEqual() 0 6 1
A notIn() 0 6 1
A range() 0 6 1
A references() 0 6 1
A size() 0 6 1
A text() 0 6 1
A type() 0 6 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ODM\MongoDB\Aggregation\Stage;
21
22
use Doctrine\ODM\MongoDB\Aggregation\Builder;
23
use Doctrine\ODM\MongoDB\Aggregation\Stage;
24
use Doctrine\ODM\MongoDB\Query\Expr;
25
use GeoJson\Geometry\Geometry;
26
27
/**
28
 * Fluent interface for building aggregation pipelines.
29
 */
30
class Match extends Stage
31
{
32
    /**
33
     * @var Expr
34
     */
35
    protected $query;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 60
    public function __construct(Builder $builder)
41
    {
42 60
        parent::__construct($builder);
43
44 60
        $this->query = $this->expr();
45 60
    }
46
47
    /**
48
     * @see http://php.net/manual/en/language.oop5.cloning.php
49
     */
50
    public function __clone()
51
    {
52
        $this->query = clone $this->query;
53
    }
54
55
    /**
56
     * Add one or more $and clauses to the current query.
57
     *
58
     * You can create a new expression using the {@link Builder::matchExpr()}
59
     * method.
60
     *
61
     * @see Expr::addAnd()
62
     * @see http://docs.mongodb.org/manual/reference/operator/and/
63
     * @param array|Expr $expression
64
     * @return $this
65
     */
66 2
    public function addAnd($expression /* , $expression2, ... */)
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68 2
        $this->query->addAnd(...func_get_args());
69
70 2
        return $this;
71
    }
72
73
    /**
74
     * Add one or more $nor clauses to the current query.
75
     *
76
     * You can create a new expression using the {@link Builder::matchExpr()}
77
     * method.
78
     *
79
     * @see Expr::addNor()
80
     * @see http://docs.mongodb.org/manual/reference/operator/nor/
81
     * @param array|Expr $expression
82
     * @return $this
83
     */
84 2
    public function addNor($expression /*, $expression2, ... */)
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86 2
        $this->query->addNor(...func_get_args());
87
88 2
        return $this;
89
    }
90
91
    /**
92
     * Add one or more $or clauses to the current query.
93
     *
94
     * You can create a new expression using the {@link Builder::matchExpr()}
95
     * method.
96
     *
97
     * @see Expr::addOr()
98
     * @see http://docs.mongodb.org/manual/reference/operator/or/
99
     * @param array|Expr $expression
100
     * @return $this
101
     */
102 3
    public function addOr($expression /* , $expression2, ... */)
0 ignored issues
show
Unused Code introduced by
The parameter $expression is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
103
    {
104 3
        $this->query->addOr(...func_get_args());
105
106 3
        return $this;
107
    }
108
109
    /**
110
     * Specify $all criteria for the current field.
111
     *
112
     * @see Expr::all()
113
     * @see http://docs.mongodb.org/manual/reference/operator/all/
114
     * @param array $values
115
     * @return $this
116
     */
117 1
    public function all(array $values)
118
    {
119 1
        $this->query->all($values);
120
121 1
        return $this;
122
    }
123
124
    /**
125
     * Return an array of information about the Builder state for debugging.
126
     *
127
     * The $name parameter may be used to return a specific key from the
128
     * internal $query array property. If omitted, the entire array will be
129
     * returned.
130
     *
131
     * @param string $name
132
     * @return mixed
133
     */
134
    public function debug($name = null)
135
    {
136
        return $name !== null ? $this->query[$name] : $this->query;
137
    }
138
139
    /**
140
     * Specify $elemMatch criteria for the current field.
141
     *
142
     * You can create a new expression using the {@link Builder::matchExpr()}
143
     * method.
144
     *
145
     * @see Expr::elemMatch()
146
     * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/
147
     * @param array|Expr $expression
148
     * @return $this
149
     */
150
    public function elemMatch($expression)
151
    {
152
        $this->query->elemMatch($expression);
153
154
        return $this;
155
    }
156
157
    /**
158
     * Specify an equality match for the current field.
159
     *
160
     * @see Expr::equals()
161
     * @param mixed $value
162
     * @return $this
163
     */
164 11
    public function equals($value)
165
    {
166 11
        $this->query->equals($value);
167
168 11
        return $this;
169
    }
170
171
    /**
172
     * Specify $exists criteria for the current field.
173
     *
174
     * @see Expr::exists()
175
     * @see http://docs.mongodb.org/manual/reference/operator/exists/
176
     * @param boolean $bool
177
     * @return $this
178
     */
179 2
    public function exists($bool)
180
    {
181 2
        $this->query->exists((boolean) $bool);
182
183 2
        return $this;
184
    }
185
186
    /**
187
     * Create a new Expr instance that can be used to build partial expressions
188
     * for other operator methods.
189
     *
190
     * @return Expr $expr
191
     */
192 60
    public function expr()
193
    {
194 60
        return $this->builder->matchExpr();
195
    }
196
197
    /**
198
     * Set the current field for building the expression.
199
     *
200
     * @see Expr::field()
201
     * @param string $field
202
     * @return $this
203
     */
204 13
    public function field($field)
205
    {
206 13
        $this->query->field((string) $field);
207
208 13
        return $this;
209
    }
210
211
    /**
212
     * Add $geoIntersects criteria with a GeoJSON geometry to the query.
213
     *
214
     * The geometry parameter GeoJSON object or an array corresponding to the
215
     * geometry's JSON representation.
216
     *
217
     * @see Expr::geoIntersects()
218
     * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/
219
     * @param array|Geometry $geometry
220
     * @return $this
221
     */
222 1
    public function geoIntersects($geometry)
223
    {
224 1
        $this->query->geoIntersects($geometry);
225
226 1
        return $this;
227
    }
228
229
    /**
230
     * Add $geoWithin criteria with a GeoJSON geometry to the query.
231
     *
232
     * The geometry parameter GeoJSON object or an array corresponding to the
233
     * geometry's JSON representation.
234
     *
235
     * @see Expr::geoWithin()
236
     * @see http://docs.mongodb.org/manual/reference/operator/geoWithin/
237
     * @param array|Geometry $geometry
238
     * @return $this
239
     */
240 1
    public function geoWithin(Geometry $geometry)
241
    {
242 1
        $this->query->geoWithin($geometry);
243
244 1
        return $this;
245
    }
246
247
    /**
248
     * Add $geoWithin criteria with a $box shape to the query.
249
     *
250
     * A rectangular polygon will be constructed from a pair of coordinates
251
     * corresponding to the bottom left and top right corners.
252
     *
253
     * Note: the $box operator only supports legacy coordinate pairs and 2d
254
     * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
255
     *
256
     * @see Expr::geoWithinBox()
257
     * @see http://docs.mongodb.org/manual/reference/operator/box/
258
     * @param float $x1
259
     * @param float $y1
260
     * @param float $x2
261
     * @param float $y2
262
     * @return $this
263
     */
264 1
    public function geoWithinBox($x1, $y1, $x2, $y2)
265
    {
266 1
        $this->query->geoWithinBox($x1, $y1, $x2, $y2);
267
268 1
        return $this;
269
    }
270
271
    /**
272
     * Add $geoWithin criteria with a $center shape to the query.
273
     *
274
     * Note: the $center operator only supports legacy coordinate pairs and 2d
275
     * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
276
     *
277
     * @see Expr::geoWithinCenter()
278
     * @see http://docs.mongodb.org/manual/reference/operator/center/
279
     * @param float $x
280
     * @param float $y
281
     * @param float $radius
282
     * @return $this
283
     */
284 1
    public function geoWithinCenter($x, $y, $radius)
285
    {
286 1
        $this->query->geoWithinCenter($x, $y, $radius);
287
288 1
        return $this;
289
    }
290
291
    /**
292
     * Add $geoWithin criteria with a $centerSphere shape to the query.
293
     *
294
     * Note: the $centerSphere operator supports both 2d and 2dsphere indexes.
295
     *
296
     * @see Expr::geoWithinCenterSphere()
297
     * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/
298
     * @param float $x
299
     * @param float $y
300
     * @param float $radius
301
     * @return $this
302
     */
303 1
    public function geoWithinCenterSphere($x, $y, $radius)
304
    {
305 1
        $this->query->geoWithinCenterSphere($x, $y, $radius);
306
307 1
        return $this;
308
    }
309
310
    /**
311
     * Add $geoWithin criteria with a $polygon shape to the query.
312
     *
313
     * Point coordinates are in x, y order (easting, northing for projected
314
     * coordinates, longitude, latitude for geographic coordinates).
315
     *
316
     * The last point coordinate is implicitly connected with the first.
317
     *
318
     * Note: the $polygon operator only supports legacy coordinate pairs and 2d
319
     * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
320
     *
321
     * @see Expr::geoWithinPolygon()
322
     * @see http://docs.mongodb.org/manual/reference/operator/polygon/
323
     * @param array $point,... Three or more point coordinate tuples
0 ignored issues
show
Bug introduced by
There is no parameter named $point,.... Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
324
     * @return $this
325
     */
326 1
    public function geoWithinPolygon(/* array($x1, $y1), ... */)
327
    {
328 1
        $this->query->geoWithinPolygon(...func_get_args());
329
330 1
        return $this;
331
    }
332
333
    /**
334
     * {@inheritdoc}
335
     */
336 9
    public function getExpression()
337
    {
338
        return [
339 9
            '$match' => $this->query->getQuery() ?: (object) [],
340
        ];
341
    }
342
343
    /**
344
     * Specify $gt criteria for the current field.
345
     *
346
     * @see Expr::gt()
347
     * @see http://docs.mongodb.org/manual/reference/operator/gt/
348
     * @param mixed $value
349
     * @return $this
350
     */
351 2
    public function gt($value)
352
    {
353 2
        $this->query->gt($value);
354
355 2
        return $this;
356
    }
357
358
    /**
359
     * Specify $gte criteria for the current field.
360
     *
361
     * @see Expr::gte()
362
     * @see http://docs.mongodb.org/manual/reference/operator/gte/
363
     * @param mixed $value
364
     * @return $this
365
     */
366 2
    public function gte($value)
367
    {
368 2
        $this->query->gte($value);
369
370 2
        return $this;
371
    }
372
373
    /**
374
     * Specify $in criteria for the current field.
375
     *
376
     * @see Expr::in()
377
     * @see http://docs.mongodb.org/manual/reference/operator/in/
378
     * @param array $values
379
     * @return $this
380
     */
381 2
    public function in(array $values)
382
    {
383 2
        $this->query->in($values);
384
385 2
        return $this;
386
    }
387
388
    /**
389
     * @param object $document
390
     * @return $this
391
     */
392
    public function includesReferenceTo($document)
393
    {
394
        $this->query->includesReferenceTo($document);
395
396
        return $this;
397
    }
398
399
    /**
400
     * Set the $language option for $text criteria.
401
     *
402
     * This method must be called after text().
403
     *
404
     * @see Expr::language()
405
     * @see http://docs.mongodb.org/manual/reference/operator/text/
406
     * @param string $language
407
     * @return $this
408
     */
409 1
    public function language($language)
410
    {
411 1
        $this->query->language($language);
412
413 1
        return $this;
414
    }
415
416
    /**
417
     * Specify $lt criteria for the current field.
418
     *
419
     * @see Expr::lte()
420
     * @see http://docs.mongodb.org/manual/reference/operator/lte/
421
     * @param mixed $value
422
     * @return $this
423
     */
424
    public function lt($value)
425
    {
426
        $this->query->lt($value);
427
428
        return $this;
429
    }
430
431
    /**
432
     * Specify $lte criteria for the current field.
433
     *
434
     * @see Expr::lte()
435
     * @see http://docs.mongodb.org/manual/reference/operator/lte/
436
     * @param mixed $value
437
     * @return $this
438
     */
439 1
    public function lte($value)
440
    {
441 1
        $this->query->lte($value);
442
443 1
        return $this;
444
    }
445
446
    /**
447
     * Add $maxDistance criteria to the query.
448
     *
449
     * If the query uses GeoJSON points, $maxDistance will be interpreted in
450
     * meters. If legacy point coordinates are used, $maxDistance will be
451
     * interpreted in radians.
452
     *
453
     * @see Expr::maxDistance()
454
     * @see http://docs.mongodb.org/manual/reference/command/geoNear/
455
     * @see http://docs.mongodb.org/manual/reference/operator/maxDistance/
456
     * @see http://docs.mongodb.org/manual/reference/operator/near/
457
     * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/
458
     * @param float $maxDistance
459
     * @return $this
460
     */
461
    public function maxDistance($maxDistance)
462
    {
463
        $this->query->maxDistance($maxDistance);
0 ignored issues
show
Bug introduced by
The method maxDistance() does not seem to exist on object<Doctrine\ODM\MongoDB\Query\Expr>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
464
465
        return $this;
466
    }
467
468
    /**
469
     * Add $minDistance criteria to the query.
470
     *
471
     * If the query uses GeoJSON points, $minDistance will be interpreted in
472
     * meters. If legacy point coordinates are used, $minDistance will be
473
     * interpreted in radians.
474
     *
475
     * @see Expr::minDistance()
476
     * @see http://docs.mongodb.org/manual/reference/command/geoNear/
477
     * @see http://docs.mongodb.org/manual/reference/operator/minDistance/
478
     * @see http://docs.mongodb.org/manual/reference/operator/near/
479
     * @see http://docs.mongodb.org/manual/reference/operator/nearSphere/
480
     * @param float $minDistance
481
     * @return $this
482
     */
483
    public function minDistance($minDistance)
484
    {
485
        $this->query->minDistance($minDistance);
0 ignored issues
show
Bug introduced by
The method minDistance() does not seem to exist on object<Doctrine\ODM\MongoDB\Query\Expr>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
486
487
        return $this;
488
    }
489
490
    /**
491
     * Specify $mod criteria for the current field.
492
     *
493
     * @see Expr::mod()
494
     * @see http://docs.mongodb.org/manual/reference/operator/mod/
495
     * @param float|integer $divisor
496
     * @param float|integer $remainder
497
     * @return $this
498
     */
499 1
    public function mod($divisor, $remainder = 0)
500
    {
501 1
        $this->query->mod($divisor, $remainder);
502
503 1
        return $this;
504
    }
505
506
    /**
507
     * Negates an expression for the current field.
508
     *
509
     * You can create a new expression using the {@link Builder::matchExpr()}
510
     * method.
511
     *
512
     * @see Expr::not()
513
     * @see http://docs.mongodb.org/manual/reference/operator/not/
514
     * @param array|Expr $expression
515
     * @return $this
516
     */
517 1
    public function not($expression)
518
    {
519 1
        $this->query->not($expression);
520
521 1
        return $this;
522
    }
523
524
    /**
525
     * Specify $ne criteria for the current field.
526
     *
527
     * @see Expr::notEqual()
528
     * @see http://docs.mongodb.org/manual/reference/operator/ne/
529
     * @param mixed $value
530
     * @return $this
531
     */
532 2
    public function notEqual($value)
533
    {
534 2
        $this->query->notEqual($value);
535
536 2
        return $this;
537
    }
538
539
    /**
540
     * Specify $nin criteria for the current field.
541
     *
542
     * @see Expr::notIn()
543
     * @see http://docs.mongodb.org/manual/reference/operator/nin/
544
     * @param array $values
545
     * @return $this
546
     */
547 1
    public function notIn(array $values)
548
    {
549 1
        $this->query->notIn($values);
550
551 1
        return $this;
552
    }
553
554
    /**
555
     * Specify $gte and $lt criteria for the current field.
556
     *
557
     * This method is shorthand for specifying $gte criteria on the lower bound
558
     * and $lt criteria on the upper bound. The upper bound is not inclusive.
559
     *
560
     * @see Expr::range()
561
     * @param mixed $start
562
     * @param mixed $end
563
     * @return $this
564
     */
565 1
    public function range($start, $end)
566
    {
567 1
        $this->query->range($start, $end);
568
569 1
        return $this;
570
    }
571
572
    /**
573
     * @param object $document
574
     * @return $this
575
     */
576
    public function references($document)
577
    {
578
        $this->query->references($document);
579
580
        return $this;
581
    }
582
583
    /**
584
     * Specify $size criteria for the current field.
585
     *
586
     * @see Expr::size()
587
     * @see http://docs.mongodb.org/manual/reference/operator/size/
588
     * @param integer $size
589
     * @return $this
590
     */
591 1
    public function size($size)
592
    {
593 1
        $this->query->size((integer) $size);
594
595 1
        return $this;
596
    }
597
598
    /**
599
     * Specify $text criteria for the current field.
600
     *
601
     * The $language option may be set with {@link Builder::language()}.
602
     *
603
     * You can only use this in the first $match stage of a pipeline.
604
     *
605
     * @see Expr::text()
606
     * @see http://docs.mongodb.org/master/reference/operator/query/text/
607
     * @param string $search
608
     * @return $this
609
     */
610 1
    public function text($search)
611
    {
612 1
        $this->query->text($search);
613
614 1
        return $this;
615
    }
616
617
    /**
618
     * Specify $type criteria for the current field.
619
     *
620
     * @see Expr::type()
621
     * @see http://docs.mongodb.org/manual/reference/operator/type/
622
     * @param integer $type
623
     * @return $this
624
     */
625 1
    public function type($type)
626
    {
627 1
        $this->query->type($type);
628
629 1
        return $this;
630
    }
631
}
632