Completed
Push — master ( 26ecbc...8c0c5d )
by Maciej
14s
created

Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php (1 issue)

Upgrade to new PHP Analysis Engine

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;
6
7
use function assert;
8
9
/**
10
 * @method Bucket groupBy($expression)
11
 */
12 View Code Duplication
class Bucket extends AbstractBucket
0 ignored issues
show
This class seems to be duplicated in your project.

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.

Loading history...
13
{
14
    /** @var array */
15
    private $boundaries;
16
17
    /** @var mixed */
18
    private $default;
19
20
    /**
21
     * An array of values based on the groupBy expression that specify the
22
     * boundaries for each bucket.
23
     *
24
     * Each adjacent pair of values acts as the inclusive lower boundary and the
25
     * exclusive upper boundary for the bucket. You must specify at least two
26
     * boundaries. The specified values must be in ascending order and all of
27
     * the same type. The exception is if the values are of mixed numeric types.
28
     *
29
     * @param array ...$boundaries
30
     */
31 4
    public function boundaries(...$boundaries) : self
32
    {
33 4
        $this->boundaries = $boundaries;
34 4
        return $this;
35
    }
36
37
    /**
38
     * A literal that specifies the _id of an additional bucket that contains
39
     * all documents whose groupBy expression result does not fall into a bucket
40
     * specified by boundaries.
41
     *
42
     * @param mixed $default
43
     */
44 3
    public function defaultBucket($default) : self
45
    {
46 3
        $this->default = $default;
47 3
        return $this;
48
    }
49
50
    /**
51
     * A document that specifies the fields to include in the output documents
52
     * in addition to the _id field. To specify the field to include, you must
53
     * use accumulator expressions.
54
     */
55 3
    public function output() : Bucket\BucketOutput
56
    {
57 3
        if (! $this->output) {
58 3
            $this->output = new Bucket\BucketOutput($this->builder, $this);
59
        }
60
61 3
        assert($this->output instanceof Bucket\BucketOutput);
62 3
        return $this->output;
63
    }
64
65 4
    protected function getExtraPipelineFields() : array
66
    {
67 4
        $fields = ['boundaries' => $this->boundaries];
68 4
        if ($this->default !== null) {
69 3
            $fields['default'] = $this->default;
70
        }
71
72 4
        return $fields;
73
    }
74
75 4
    protected function getStageName() : string
76
    {
77 4
        return '$bucket';
78
    }
79
}
80