These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Doctrine\ODM\MongoDB\Aggregation\Stage\Bucket; |
||
6 | |||
7 | use Doctrine\ODM\MongoDB\Aggregation\Builder; |
||
8 | use Doctrine\ODM\MongoDB\Aggregation\Expr; |
||
9 | use Doctrine\ODM\MongoDB\Aggregation\Stage; |
||
10 | use function assert; |
||
11 | |||
12 | /** |
||
13 | * Fluent interface for adding an output specification to a bucket stage. |
||
14 | */ |
||
15 | View Code Duplication | class BucketOutput extends AbstractOutput |
|
0 ignored issues
–
show
|
|||
16 | { |
||
17 | 3 | public function __construct(Builder $builder, Stage\Bucket $bucket) |
|
18 | { |
||
19 | 3 | parent::__construct($builder, $bucket); |
|
20 | 3 | } |
|
21 | |||
22 | /** |
||
23 | * An expression to group documents by. To specify a field path, prefix the |
||
24 | * field name with a dollar sign $ and enclose it in quotes. |
||
25 | * |
||
26 | * @param mixed|Expr $expression |
||
27 | * |
||
28 | * @return Stage\Bucket |
||
29 | */ |
||
30 | public function groupBy($expression) |
||
31 | { |
||
32 | assert($this->bucket instanceof Stage\Bucket); |
||
33 | return $this->bucket->groupBy($expression); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * An array of values based on the groupBy expression that specify the |
||
38 | * boundaries for each bucket. |
||
39 | * |
||
40 | * Each adjacent pair of values acts as the inclusive lower boundary and the |
||
41 | * exclusive upper boundary for the bucket. You must specify at least two |
||
42 | * boundaries. The specified values must be in ascending order and all of |
||
43 | * the same type. The exception is if the values are of mixed numeric types. |
||
44 | * |
||
45 | * @param array ...$boundaries |
||
46 | * |
||
47 | * @return Stage\Bucket |
||
48 | */ |
||
49 | public function boundaries(...$boundaries) |
||
50 | { |
||
51 | assert($this->bucket instanceof Stage\Bucket); |
||
52 | return $this->bucket->boundaries(...$boundaries); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * A literal that specifies the _id of an additional bucket that contains |
||
57 | * all documents whose groupBy expression result does not fall into a bucket |
||
58 | * specified by boundaries. |
||
59 | * |
||
60 | * @param mixed $default |
||
61 | * |
||
62 | * @return Stage\Bucket |
||
63 | */ |
||
64 | public function defaultBucket($default) |
||
65 | { |
||
66 | assert($this->bucket instanceof Stage\Bucket); |
||
67 | return $this->bucket->defaultBucket($default); |
||
68 | } |
||
69 | } |
||
70 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.