Code Duplication    Length = 59-68 lines in 2 locations

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php 1 location

@@ 12-79 (lines=68) @@
9
/**
10
 * @method Bucket groupBy($expression)
11
 */
12
class Bucket extends AbstractBucket
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
    public function boundaries(...$boundaries) : self
32
    {
33
        $this->boundaries = $boundaries;
34
        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
    public function defaultBucket($default) : self
45
    {
46
        $this->default = $default;
47
        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
    public function output() : Bucket\BucketOutput
56
    {
57
        if (! $this->output) {
58
            $this->output = new Bucket\BucketOutput($this->builder, $this);
59
        }
60
61
        assert($this->output instanceof Bucket\BucketOutput);
62
        return $this->output;
63
    }
64
65
    protected function getExtraPipelineFields() : array
66
    {
67
        $fields = ['boundaries' => $this->boundaries];
68
        if ($this->default !== null) {
69
            $fields['default'] = $this->default;
70
        }
71
72
        return $fields;
73
    }
74
75
    protected function getStageName() : string
76
    {
77
        return '$bucket';
78
    }
79
}
80

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php 1 location

@@ 12-70 (lines=59) @@
9
/**
10
 * @method BucketAuto groupBy($expression)
11
 */
12
class BucketAuto extends AbstractBucket
13
{
14
    /** @var int */
15
    private $buckets;
16
17
    /** @var string */
18
    private $granularity;
19
20
    /**
21
     * A positive 32-bit integer that specifies the number of buckets into which
22
     * input documents are grouped.
23
     */
24
    public function buckets(int $buckets) : self
25
    {
26
        $this->buckets = $buckets;
27
        return $this;
28
    }
29
30
    /**
31
     * A string that specifies the preferred number series to use to ensure that
32
     * the calculated boundary edges end on preferred round numbers or their
33
     * powers of 10.
34
     */
35
    public function granularity(string $granularity) : self
36
    {
37
        $this->granularity = $granularity;
38
        return $this;
39
    }
40
41
    /**
42
     * A document that specifies the fields to include in the output documents
43
     * in addition to the _id field. To specify the field to include, you must
44
     * use accumulator expressions.
45
     */
46
    public function output() : Bucket\BucketAutoOutput
47
    {
48
        if (! $this->output) {
49
            $this->output = new Bucket\BucketAutoOutput($this->builder, $this);
50
        }
51
52
        assert($this->output instanceof Bucket\BucketAutoOutput);
53
        return $this->output;
54
    }
55
56
    protected function getExtraPipelineFields() : array
57
    {
58
        $fields = ['buckets' => $this->buckets];
59
        if ($this->granularity !== null) {
60
            $fields['granularity'] = $this->granularity;
61
        }
62
63
        return $fields;
64
    }
65
66
    protected function getStageName() : string
67
    {
68
        return '$bucketAuto';
69
    }
70
}
71