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

ODM/MongoDB/Aggregation/Stage/BucketAuto.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 BucketAuto groupBy($expression)
11
 */
12 View Code Duplication
class BucketAuto 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 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 4
    public function buckets(int $buckets) : self
25
    {
26 4
        $this->buckets = $buckets;
27 4
        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 3
    public function granularity(string $granularity) : self
36
    {
37 3
        $this->granularity = $granularity;
38 3
        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 3
    public function output() : Bucket\BucketAutoOutput
47
    {
48 3
        if (! $this->output) {
49 3
            $this->output = new Bucket\BucketAutoOutput($this->builder, $this);
50
        }
51
52 3
        assert($this->output instanceof Bucket\BucketAutoOutput);
53 3
        return $this->output;
54
    }
55
56 4
    protected function getExtraPipelineFields() : array
57
    {
58 4
        $fields = ['buckets' => $this->buckets];
59 4
        if ($this->granularity !== null) {
60 3
            $fields['granularity'] = $this->granularity;
61
        }
62
63 4
        return $fields;
64
    }
65
66 4
    protected function getStageName() : string
67
    {
68 4
        return '$bucketAuto';
69
    }
70
}
71