AbstractOutput   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 246
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 30.23%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 3
dl 0
loc 246
ccs 13
cts 43
cp 0.3023
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getExpression() 0 4 1
A addToSet() 0 6 1
A avg() 0 6 1
A expression() 0 6 1
A field() 0 6 1
A first() 0 6 1
A last() 0 6 1
A max() 0 6 1
A min() 0 6 1
A push() 0 6 1
A stdDevPop() 0 6 1
A stdDevSamp() 0 6 1
A sum() 0 6 1
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
11
/**
12
 * Abstract class with common functionality for output objects in bucket stages
13
 *
14
 * @internal
15
 */
16
abstract class AbstractOutput extends Stage
17
{
18
    /** @var Stage\AbstractBucket */
19
    protected $bucket;
20
21
    /** @var Expr */
22
    private $expr;
23
24 6
    public function __construct(Builder $builder, Stage\AbstractBucket $bucket)
25
    {
26 6
        parent::__construct($builder);
27
28 6
        $this->bucket = $bucket;
29 6
        $this->expr   = $builder->expr();
30 6
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 6
    public function getExpression() : array
36
    {
37 6
        return $this->expr->getExpression();
38
    }
39
40
    /**
41
     * Returns an array of all unique values that results from applying an
42
     * expression to each document in a group of documents that share the same
43
     * group by key. Order of the elements in the output array is unspecified.
44
     *
45
     * AddToSet is an accumulator operation only available in the group stage.
46
     *
47
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/addToSet/
48
     * @see Expr::addToSet
49
     *
50
     * @param mixed|Expr $expression
51
     *
52
     * @return $this
53
     */
54
    public function addToSet($expression)
55
    {
56
        $this->expr->addToSet($expression);
57
58
        return $this;
59
    }
60
61
    /**
62
     * Returns the average value of the numeric values that result from applying
63
     * a specified expression to each document in a group of documents that
64
     * share the same group by key. Ignores nun-numeric values.
65
     *
66
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/avg/
67
     * @see Expr::avg
68
     *
69
     * @param mixed|Expr $expression
70
     *
71
     * @return $this
72
     */
73 6
    public function avg($expression)
74
    {
75 6
        $this->expr->avg($expression);
76
77 6
        return $this;
78
    }
79
80
    /**
81
     * Used to use an expression as field value. Can be any expression.
82
     *
83
     * @see http://docs.mongodb.org/manual/meta/aggregation-quick-reference/#aggregation-expressions
84
     * @see Expr::expression
85
     *
86
     * @param mixed|Expr $value
87
     *
88
     * @return $this
89
     */
90
    public function expression($value)
91
    {
92
        $this->expr->expression($value);
93
94
        return $this;
95
    }
96
97
    /**
98
     * Set the current field for building the expression.
99
     *
100
     * @see Expr::field
101
     *
102
     * @param string $fieldName
103
     *
104
     * @return $this
105
     */
106 6
    public function field($fieldName)
107
    {
108 6
        $this->expr->field($fieldName);
109
110 6
        return $this;
111
    }
112
113
    /**
114
     * Returns the value that results from applying an expression to the first
115
     * document in a group of documents that share the same group by key. Only
116
     * meaningful when documents are in a defined order.
117
     *
118
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/first/
119
     * @see Expr::first
120
     *
121
     * @param mixed|Expr $expression
122
     *
123
     * @return $this
124
     */
125
    public function first($expression)
126
    {
127
        $this->expr->first($expression);
128
129
        return $this;
130
    }
131
132
    /**
133
     * Returns the value that results from applying an expression to the last
134
     * document in a group of documents that share the same group by a field.
135
     * Only meaningful when documents are in a defined order.
136
     *
137
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/last/
138
     * @see Expr::last
139
     *
140
     * @param mixed|Expr $expression
141
     *
142
     * @return $this
143
     */
144
    public function last($expression)
145
    {
146
        $this->expr->last($expression);
147
148
        return $this;
149
    }
150
151
    /**
152
     * Returns the highest value that results from applying an expression to
153
     * each document in a group of documents that share the same group by key.
154
     *
155
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/max/
156
     * @see Expr::max
157
     *
158
     * @param mixed|Expr $expression
159
     *
160
     * @return $this
161
     */
162
    public function max($expression)
163
    {
164
        $this->expr->max($expression);
165
166
        return $this;
167
    }
168
169
    /**
170
     * Returns the lowest value that results from applying an expression to each
171
     * document in a group of documents that share the same group by key.
172
     *
173
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/min/
174
     * @see Expr::min
175
     *
176
     * @param mixed|Expr $expression
177
     *
178
     * @return $this
179
     */
180
    public function min($expression)
181
    {
182
        $this->expr->min($expression);
183
184
        return $this;
185
    }
186
187
    /**
188
     * Returns an array of all values that result from applying an expression to
189
     * each document in a group of documents that share the same group by key.
190
     *
191
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/push/
192
     * @see Expr::push
193
     *
194
     * @param mixed|Expr $expression
195
     *
196
     * @return $this
197
     */
198
    public function push($expression)
199
    {
200
        $this->expr->push($expression);
201
202
        return $this;
203
    }
204
205
    /**
206
     * Calculates the population standard deviation of the input values.
207
     *
208
     * The argument can be any expression as long as it resolves to an array.
209
     *
210
     * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevPop/
211
     * @see Expr::stdDevPop
212
     *
213
     * @param mixed|Expr $expression
214
     *
215
     * @return $this
216
     */
217
    public function stdDevPop($expression)
218
    {
219
        $this->expr->stdDevPop($expression);
220
221
        return $this;
222
    }
223
224
    /**
225
     * Calculates the sample standard deviation of the input values.
226
     *
227
     * The argument can be any expression as long as it resolves to an array.
228
     *
229
     * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/
230
     * @see Expr::stdDevSamp
231
     *
232
     * @param mixed|Expr $expression
233
     *
234
     * @return $this
235
     */
236
    public function stdDevSamp($expression)
237
    {
238
        $this->expr->stdDevSamp($expression);
239
240
        return $this;
241
    }
242
243
    /**
244
     * Calculates and returns the sum of all the numeric values that result from
245
     * applying a specified expression to each document in a group of documents
246
     * that share the same group by key. Ignores nun-numeric values.
247
     *
248
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/
249
     * @see Expr::sum
250
     *
251
     * @param mixed|Expr $expression
252
     *
253
     * @return $this
254
     */
255
    public function sum($expression)
256
    {
257
        $this->expr->sum($expression);
258
259
        return $this;
260
    }
261
}
262