Match   A
last analyzed

Complexity

Total Complexity 35

Size/Duplication

Total Lines 506
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 85.15%

Importance

Changes 0
Metric Value
wmc 35
lcom 2
cbo 3
dl 0
loc 506
ccs 86
cts 101
cp 0.8515
rs 9.6
c 0
b 0
f 0

34 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 exists() 0 6 1
A in() 0 6 1
A elemMatch() 0 6 1
A equals() 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 includesReferenceTo() 0 6 1
A language() 0 6 1
A lt() 0 6 1
A lte() 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
declare(strict_types=1);
4
5
namespace Doctrine\ODM\MongoDB\Aggregation\Stage;
6
7
use Doctrine\ODM\MongoDB\Aggregation\Builder;
8
use Doctrine\ODM\MongoDB\Aggregation\Stage;
9
use Doctrine\ODM\MongoDB\Query\Expr;
10
use GeoJson\Geometry\Geometry;
11
use function func_get_args;
12
13
/**
14
 * Fluent interface for building aggregation pipelines.
15
 */
16
class Match extends Stage
17
{
18
    /** @var Expr */
19
    protected $query;
20
21
    /**
22
     * {@inheritdoc}
23
     */
24 61
    public function __construct(Builder $builder)
25
    {
26 61
        parent::__construct($builder);
27
28 61
        $this->query = $this->expr();
29 61
    }
30
31
    /**
32
     * @see http://php.net/manual/en/language.oop5.cloning.php
33
     */
34
    public function __clone()
35
    {
36
        $this->query = clone $this->query;
37
    }
38
39
    /**
40
     * Add one or more $and clauses to the current query.
41
     *
42
     * You can create a new expression using the {@link Builder::matchExpr()}
43
     * method.
44
     *
45
     * @see Expr::addAnd()
46
     * @see http://docs.mongodb.org/manual/reference/operator/and/
47
     *
48
     * @param array|Expr $expression
49
     * @param array|Expr ...$expressions
50
     */
51 2
    public function addAnd($expression, ...$expressions) : self
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...
Unused Code introduced by
The parameter $expressions 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...
52
    {
53 2
        $this->query->addAnd(...func_get_args());
54
55 2
        return $this;
56
    }
57
58
    /**
59
     * Add one or more $nor clauses to the current query.
60
     *
61
     * You can create a new expression using the {@link Builder::matchExpr()}
62
     * method.
63
     *
64
     * @see Expr::addNor()
65
     * @see http://docs.mongodb.org/manual/reference/operator/nor/
66
     *
67
     * @param array|Expr $expression
68
     * @param array|Expr ...$expressions
69
     */
70 2
    public function addNor($expression, ...$expressions) : self
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...
Unused Code introduced by
The parameter $expressions 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...
71
    {
72 2
        $this->query->addNor(...func_get_args());
73
74 2
        return $this;
75
    }
76
77
    /**
78
     * Add one or more $or clauses to the current query.
79
     *
80
     * You can create a new expression using the {@link Builder::matchExpr()}
81
     * method.
82
     *
83
     * @see Expr::addOr()
84
     * @see http://docs.mongodb.org/manual/reference/operator/or/
85
     *
86
     * @param array|Expr $expression
87
     * @param array|Expr ...$expressions
88
     */
89 3
    public function addOr($expression, ...$expressions) : self
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...
Unused Code introduced by
The parameter $expressions 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...
90
    {
91 3
        $this->query->addOr(...func_get_args());
92
93 3
        return $this;
94
    }
95
96
    /**
97
     * Specify $all criteria for the current field.
98
     *
99
     * @see Expr::all()
100
     * @see http://docs.mongodb.org/manual/reference/operator/all/
101
     */
102 1
    public function all(array $values) : self
103
    {
104 1
        $this->query->all($values);
105
106 1
        return $this;
107
    }
108
109
    /**
110
     * Specify $elemMatch criteria for the current field.
111
     *
112
     * You can create a new expression using the {@link Builder::matchExpr()}
113
     * method.
114
     *
115
     * @see Expr::elemMatch()
116
     * @see http://docs.mongodb.org/manual/reference/operator/elemMatch/
117
     *
118
     * @param array|Expr $expression
119
     */
120
    public function elemMatch($expression) : self
121
    {
122
        $this->query->elemMatch($expression);
123
124
        return $this;
125
    }
126
127
    /**
128
     * Specify an equality match for the current field.
129
     *
130
     * @see Expr::equals()
131
     *
132
     * @param mixed $value
133
     */
134 11
    public function equals($value) : self
135
    {
136 11
        $this->query->equals($value);
137
138 11
        return $this;
139
    }
140
141
    /**
142
     * Specify $exists criteria for the current field.
143
     *
144
     * @see Expr::exists()
145
     * @see http://docs.mongodb.org/manual/reference/operator/exists/
146
     */
147 2
    public function exists(bool $bool) : self
148
    {
149 2
        $this->query->exists($bool);
150
151 2
        return $this;
152
    }
153
154
    /**
155
     * Create a new Expr instance that can be used to build partial expressions
156
     * for other operator methods.
157
     */
158 61
    public function expr() : Expr
159
    {
160 61
        return $this->builder->matchExpr();
161
    }
162
163
    /**
164
     * Set the current field for building the expression.
165
     *
166
     * @see Expr::field()
167
     */
168 13
    public function field(string $field) : self
169
    {
170 13
        $this->query->field($field);
171
172 13
        return $this;
173
    }
174
175
    /**
176
     * Add $geoIntersects criteria with a GeoJSON geometry to the query.
177
     *
178
     * The geometry parameter GeoJSON object or an array corresponding to the
179
     * geometry's JSON representation.
180
     *
181
     * @see Expr::geoIntersects()
182
     * @see http://docs.mongodb.org/manual/reference/operator/geoIntersects/
183
     *
184
     * @param array|Geometry $geometry
185
     */
186 1
    public function geoIntersects($geometry) : self
187
    {
188 1
        $this->query->geoIntersects($geometry);
189
190 1
        return $this;
191
    }
192
193
    /**
194
     * Add $geoWithin criteria with a GeoJSON geometry to the query.
195
     *
196
     * The geometry parameter GeoJSON object or an array corresponding to the
197
     * geometry's JSON representation.
198
     *
199
     * @see Expr::geoWithin()
200
     * @see http://docs.mongodb.org/manual/reference/operator/geoWithin/
201
     */
202 1
    public function geoWithin(Geometry $geometry) : self
203
    {
204 1
        $this->query->geoWithin($geometry);
205
206 1
        return $this;
207
    }
208
209
    /**
210
     * Add $geoWithin criteria with a $box shape to the query.
211
     *
212
     * A rectangular polygon will be constructed from a pair of coordinates
213
     * corresponding to the bottom left and top right corners.
214
     *
215
     * Note: the $box operator only supports legacy coordinate pairs and 2d
216
     * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
217
     *
218
     * @see Expr::geoWithinBox()
219
     * @see http://docs.mongodb.org/manual/reference/operator/box/
220
     */
221 1
    public function geoWithinBox(float $x1, float $y1, float $x2, float $y2) : self
222
    {
223 1
        $this->query->geoWithinBox($x1, $y1, $x2, $y2);
224
225 1
        return $this;
226
    }
227
228
    /**
229
     * Add $geoWithin criteria with a $center shape to the query.
230
     *
231
     * Note: the $center operator only supports legacy coordinate pairs and 2d
232
     * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
233
     *
234
     * @see Expr::geoWithinCenter()
235
     * @see http://docs.mongodb.org/manual/reference/operator/center/
236
     */
237 1
    public function geoWithinCenter(float $x, float $y, float $radius) : self
238
    {
239 1
        $this->query->geoWithinCenter($x, $y, $radius);
240
241 1
        return $this;
242
    }
243
244
    /**
245
     * Add $geoWithin criteria with a $centerSphere shape to the query.
246
     *
247
     * Note: the $centerSphere operator supports both 2d and 2dsphere indexes.
248
     *
249
     * @see Expr::geoWithinCenterSphere()
250
     * @see http://docs.mongodb.org/manual/reference/operator/centerSphere/
251
     */
252 1
    public function geoWithinCenterSphere(float $x, float $y, float $radius) : self
253
    {
254 1
        $this->query->geoWithinCenterSphere($x, $y, $radius);
255
256 1
        return $this;
257
    }
258
259
    /**
260
     * Add $geoWithin criteria with a $polygon shape to the query.
261
     *
262
     * Point coordinates are in x, y order (easting, northing for projected
263
     * coordinates, longitude, latitude for geographic coordinates).
264
     *
265
     * The last point coordinate is implicitly connected with the first.
266
     *
267
     * Note: the $polygon operator only supports legacy coordinate pairs and 2d
268
     * indexes. This cannot be used with 2dsphere indexes and GeoJSON shapes.
269
     *
270
     * @see Expr::geoWithinPolygon()
271
     * @see http://docs.mongodb.org/manual/reference/operator/polygon/
272
     *
273
     * @param array $point1    First point of the polygon
274
     * @param array $point2    Second point of the polygon
275
     * @param array $point3    Third point of the polygon
276
     * @param array ...$points Additional points of the polygon
277
     */
278 1
    public function geoWithinPolygon($point1, $point2, $point3, ...$points) : self
0 ignored issues
show
Unused Code introduced by
The parameter $point1 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...
Unused Code introduced by
The parameter $point2 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...
Unused Code introduced by
The parameter $point3 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...
Unused Code introduced by
The parameter $points 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...
279
    {
280 1
        $this->query->geoWithinPolygon(...func_get_args());
281
282 1
        return $this;
283
    }
284
285
    /**
286
     * {@inheritdoc}
287
     */
288 10
    public function getExpression() : array
289
    {
290
        return [
291 10
            '$match' => $this->query->getQuery() ?: (object) [],
292
        ];
293
    }
294
295
    /**
296
     * Specify $gt criteria for the current field.
297
     *
298
     * @see Expr::gt()
299
     * @see http://docs.mongodb.org/manual/reference/operator/gt/
300
     *
301
     * @param mixed $value
302
     */
303 2
    public function gt($value) : self
304
    {
305 2
        $this->query->gt($value);
306
307 2
        return $this;
308
    }
309
310
    /**
311
     * Specify $gte criteria for the current field.
312
     *
313
     * @see Expr::gte()
314
     * @see http://docs.mongodb.org/manual/reference/operator/gte/
315
     *
316
     * @param mixed $value
317
     */
318 2
    public function gte($value) : self
319
    {
320 2
        $this->query->gte($value);
321
322 2
        return $this;
323
    }
324
325
    /**
326
     * Specify $in criteria for the current field.
327
     *
328
     * @see Expr::in()
329
     * @see http://docs.mongodb.org/manual/reference/operator/in/
330
     */
331 2
    public function in(array $values) : self
332
    {
333 2
        $this->query->in($values);
334
335 2
        return $this;
336
    }
337
338
    public function includesReferenceTo(object $document) : self
339
    {
340
        $this->query->includesReferenceTo($document);
341
342
        return $this;
343
    }
344
345
    /**
346
     * Set the $language option for $text criteria.
347
     *
348
     * This method must be called after text().
349
     *
350
     * @see Expr::language()
351
     * @see http://docs.mongodb.org/manual/reference/operator/text/
352
     */
353 1
    public function language(string $language) : self
354
    {
355 1
        $this->query->language($language);
356
357 1
        return $this;
358
    }
359
360
    /**
361
     * Specify $lt criteria for the current field.
362
     *
363
     * @see Expr::lte()
364
     * @see http://docs.mongodb.org/manual/reference/operator/lte/
365
     *
366
     * @param mixed $value
367
     */
368
    public function lt($value) : self
369
    {
370
        $this->query->lt($value);
371
372
        return $this;
373
    }
374
375
    /**
376
     * Specify $lte criteria for the current field.
377
     *
378
     * @see Expr::lte()
379
     * @see http://docs.mongodb.org/manual/reference/operator/lte/
380
     *
381
     * @param mixed $value
382
     */
383 1
    public function lte($value) : self
384
    {
385 1
        $this->query->lte($value);
386
387 1
        return $this;
388
    }
389
390
    /**
391
     * Specify $mod criteria for the current field.
392
     *
393
     * @see Expr::mod()
394
     * @see http://docs.mongodb.org/manual/reference/operator/mod/
395
     *
396
     * @param float|int $divisor
397
     * @param float|int $remainder
398
     */
399 1
    public function mod($divisor, $remainder = 0) : self
400
    {
401 1
        $this->query->mod($divisor, $remainder);
402
403 1
        return $this;
404
    }
405
406
    /**
407
     * Negates an expression for the current field.
408
     *
409
     * You can create a new expression using the {@link Builder::matchExpr()}
410
     * method.
411
     *
412
     * @see Expr::not()
413
     * @see http://docs.mongodb.org/manual/reference/operator/not/
414
     *
415
     * @param array|Expr $expression
416
     */
417 1
    public function not($expression) : self
418
    {
419 1
        $this->query->not($expression);
420
421 1
        return $this;
422
    }
423
424
    /**
425
     * Specify $ne criteria for the current field.
426
     *
427
     * @see Expr::notEqual()
428
     * @see http://docs.mongodb.org/manual/reference/operator/ne/
429
     *
430
     * @param mixed $value
431
     */
432 2
    public function notEqual($value) : self
433
    {
434 2
        $this->query->notEqual($value);
435
436 2
        return $this;
437
    }
438
439
    /**
440
     * Specify $nin criteria for the current field.
441
     *
442
     * @see Expr::notIn()
443
     * @see http://docs.mongodb.org/manual/reference/operator/nin/
444
     */
445 1
    public function notIn(array $values) : self
446
    {
447 1
        $this->query->notIn($values);
448
449 1
        return $this;
450
    }
451
452
    /**
453
     * Specify $gte and $lt criteria for the current field.
454
     *
455
     * This method is shorthand for specifying $gte criteria on the lower bound
456
     * and $lt criteria on the upper bound. The upper bound is not inclusive.
457
     *
458
     * @see Expr::range()
459
     *
460
     * @param mixed $start
461
     * @param mixed $end
462
     */
463 1
    public function range($start, $end) : self
464
    {
465 1
        $this->query->range($start, $end);
466
467 1
        return $this;
468
    }
469
470
    public function references(object $document) : self
471
    {
472
        $this->query->references($document);
473
474
        return $this;
475
    }
476
477
    /**
478
     * Specify $size criteria for the current field.
479
     *
480
     * @see Expr::size()
481
     * @see http://docs.mongodb.org/manual/reference/operator/size/
482
     */
483 1
    public function size(int $size) : self
484
    {
485 1
        $this->query->size($size);
486
487 1
        return $this;
488
    }
489
490
    /**
491
     * Specify $text criteria for the current field.
492
     *
493
     * The $language option may be set with {@link Builder::language()}.
494
     *
495
     * You can only use this in the first $match stage of a pipeline.
496
     *
497
     * @see Expr::text()
498
     * @see http://docs.mongodb.org/master/reference/operator/query/text/
499
     */
500 1
    public function text(string $search) : self
501
    {
502 1
        $this->query->text($search);
503
504 1
        return $this;
505
    }
506
507
    /**
508
     * Specify $type criteria for the current field.
509
     *
510
     * @see Expr::type()
511
     * @see http://docs.mongodb.org/manual/reference/operator/type/
512
     *
513
     * @param int|string $type
514
     */
515 1
    public function type($type) : self
516
    {
517 1
        $this->query->type($type);
518
519 1
        return $this;
520
    }
521
}
522