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

Project::stdDevSamp()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license. For more information, see
17
 * <http://www.doctrine-project.org>.
18
 */
19
20
namespace Doctrine\ODM\MongoDB\Aggregation\Stage;
21
22
use Doctrine\ODM\MongoDB\Aggregation\Expr;
23
24
/**
25
 * Fluent interface for adding a $project stage to an aggregation pipeline.
26
 *
27
 * @author alcaeus <[email protected]>
28
 * @since 1.2
29
 */
30
class Project extends Operator
31
{
32
    /**
33
     * {@inheritdoc}
34
     */
35 11
    public function getExpression()
36
    {
37
        return [
38 11
            '$project' => $this->expr->getExpression()
39
        ];
40
    }
41
42
    /**
43
     * Returns the average value of the numeric values that result from applying
44
     * a specified expression to each document in a group of documents that
45
     * share the same group by key. Ignores nun-numeric values.
46
     *
47
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/avg/
48
     * @see Expr::avg
49
     * @param mixed|Expr $expression1
50
     * @param mixed|Expr $expression2, ... Additional expressions
0 ignored issues
show
Bug introduced by
There is no parameter named $expression2,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
51
     * @return $this
52
     *
53
     * @since 1.3
54
     */
55 2
    public function avg($expression1/* , $expression2, ... */)
56
    {
57 2
        $this->expr->avg(func_num_args() === 1 ? $expression1 : func_get_args());
58
59 2
        return $this;
60
    }
61
62
    /**
63
     * Shorthand method to exclude the _id field.
64
     *
65
     * @deprecated Deprecated in 1.5, please use {@link excludeFields()}.
66
     * @param bool $exclude
67
     * @return $this
68
     */
69 2
    public function excludeIdField($exclude = true)
70
    {
71 2
        @trigger_error(__METHOD__ . ' has been deprecated in favor of excludeFields.', E_USER_DEPRECATED);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
72
73 2
        return $this->field('_id')->expression( ! $exclude);
74
    }
75
76
    /**
77
     * Shorthand method to define which fields to be included.
78
     *
79
     * @param array $fields
80
     * @return $this
81
     */
82 4
    public function includeFields(array $fields)
83
    {
84 4
        foreach ($fields as $fieldName) {
85 4
            $this->field($fieldName)->expression(true);
86
        }
87
88 4
        return $this;
89
    }
90
91
    /**
92
     * Shorthand method to define which fields to be excluded.
93
     *
94
     * If you specify the exclusion of a field other than _id, you cannot employ
95
     * any other $project specification forms.
96
     *
97
     * @since 1.5
98
     * @param array $fields
99
     * @return $this
100
     */
101 2
    public function excludeFields(array $fields)
102
    {
103 2
        foreach ($fields as $fieldName) {
104 2
            $this->field($fieldName)->expression(false);
105
        }
106
107 2
        return $this;
108
    }
109
110
    /**
111
     * Returns the highest value that results from applying an expression to
112
     * each document in a group of documents that share the same group by key.
113
     *
114
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/max/
115
     * @see Expr::max
116
     * @param mixed|Expr $expression1
117
     * @param mixed|Expr $expression2, ... Additional expressions
0 ignored issues
show
Bug introduced by
There is no parameter named $expression2,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
118
     * @return $this
119
     *
120
     * @since 1.3
121
     */
122 2
    public function max($expression1/* , $expression2, ... */)
123
    {
124 2
        $this->expr->max(func_num_args() === 1 ? $expression1 : func_get_args());
125
126 2
        return $this;
127
    }
128
129
    /**
130
     * Returns the lowest value that results from applying an expression to each
131
     * document in a group of documents that share the same group by key.
132
     *
133
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/min/
134
     * @see Expr::min
135
     * @param mixed|Expr $expression1
136
     * @param mixed|Expr $expression2, ... Additional expressions
0 ignored issues
show
Bug introduced by
There is no parameter named $expression2,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
137
     * @return $this
138
     *
139
     * @since 1.3
140
     */
141 2
    public function min($expression1/* , $expression2, ... */)
142
    {
143 2
        $this->expr->min(func_num_args() === 1 ? $expression1 : func_get_args());
144
145 2
        return $this;
146
    }
147
148
    /**
149
     * Calculates the population standard deviation of the input values.
150
     *
151
     * The argument can be any expression as long as it resolves to an array.
152
     *
153
     * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevPop/
154
     * @see Expr::stdDevPop
155
     * @param mixed|Expr $expression1
156
     * @param mixed|Expr $expression2, ... Additional expressions
0 ignored issues
show
Bug introduced by
There is no parameter named $expression2,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
157
     * @return $this
158
     *
159
     * @since 1.3
160
     */
161 2
    public function stdDevPop($expression1/* , $expression2, ... */)
162
    {
163 2
        $this->expr->stdDevPop(func_num_args() === 1 ? $expression1 : func_get_args());
164
165 2
        return $this;
166
    }
167
168
    /**
169
     * Calculates the sample standard deviation of the input values.
170
     *
171
     * The argument can be any expression as long as it resolves to an array.
172
     *
173
     * @see https://docs.mongodb.org/manual/reference/operator/aggregation/stdDevSamp/
174
     * @see Expr::stdDevSamp
175
     * @param mixed|Expr $expression1
176
     * @param mixed|Expr $expression2, ... Additional expressions
0 ignored issues
show
Bug introduced by
There is no parameter named $expression2,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
177
     * @return $this
178
     *
179
     * @since 1.3
180
     */
181 2
    public function stdDevSamp($expression1/* , $expression2, ... */)
182
    {
183 2
        $this->expr->stdDevSamp(func_num_args() === 1 ? $expression1 : func_get_args());
184
185 2
        return $this;
186
    }
187
188
    /**
189
     * Calculates and returns the sum of all the numeric values that result from
190
     * applying a specified expression to each document in a group of documents
191
     * that share the same group by key. Ignores nun-numeric values.
192
     *
193
     * @see http://docs.mongodb.org/manual/reference/operator/aggregation/sum/
194
     * @see Expr::sum
195
     * @param mixed|Expr $expression1
196
     * @param mixed|Expr $expression2, ... Additional expressions
0 ignored issues
show
Bug introduced by
There is no parameter named $expression2,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
197
     * @return $this
198
     *
199
     * @since 1.3
200
     */
201 2
    public function sum($expression1/* , $expression2, ... */)
202
    {
203 2
        $this->expr->sum(func_num_args() === 1 ? $expression1 : func_get_args());
204
205 2
        return $this;
206
    }
207
}
208