Completed
Push — master ( 11f27c...4713a5 )
by Andreas
08:33
created

AbstractOutput   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 254
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 30.23%

Importance

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

14 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 7 7 1
A getExpression() 4 4 1
A addToSet() 6 6 1
A avg() 6 6 1
A expression() 6 6 1
A field() 6 6 1
A first() 6 6 1
A last() 6 6 1
A max() 6 6 1
A min() 6 6 1
A push() 6 6 1
A stdDevPop() 6 6 1
A stdDevSamp() 6 6 1
A sum() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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