Completed
Push — develop ( 03f96a...8c66af )
by Adrien
19:36
created

Database   C

Complexity

Total Complexity 44

Size/Duplication

Total Lines 628
Duplicated Lines 11.46 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 72
loc 628
ccs 0
cts 126
cp 0
rs 6.195
c 0
b 0
f 0
wmc 44
lcom 1
cbo 4

15 Methods

Rating   Name   Duplication   Size   Complexity  
A fieldExtract() 0 14 3
D filter() 0 54 13
A getFilteredColumn() 0 12 2
A DAVERAGE() 0 12 2
A DCOUNT() 12 12 2
A DCOUNTA() 0 20 3
A DGET() 0 15 3
A DMAX() 12 12 2
A DMIN() 12 12 2
A DPRODUCT() 12 12 2
A DSTDEV() 0 12 2
A DSTDEVP() 0 12 2
A DSUM() 12 12 2
A DVAR() 0 12 2
A DVARP() 12 12 2

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Database often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Database, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation;
4
5
/**
6
 * Copyright (c) 2006 - 2016 PhpSpreadsheet.
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 *
22
 * @category    PhpSpreadsheet
23
 *
24
 * @copyright    Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
25
 * @license        http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
26
 */
27
class Database
28
{
29
    /**
30
     * fieldExtract.
31
     *
32
     * Extracts the column ID to use for the data field.
33
     *
34
     * @param    mixed[]        $database        The range of cells that makes up the list or database.
35
     *                                        A database is a list of related data in which rows of related
36
     *                                        information are records, and columns of data are fields. The
37
     *                                        first row of the list contains labels for each column.
38
     * @param    mixed        $field            Indicates which column is used in the function. Enter the
39
     *                                        column label enclosed between double quotation marks, such as
40
     *                                        "Age" or "Yield," or a number (without quotation marks) that
41
     *                                        represents the position of the column within the list: 1 for
42
     *                                        the first column, 2 for the second column, and so on.
43
     *
44
     * @return    string|null
45
     */
46
    private static function fieldExtract($database, $field)
47
    {
48
        $field = strtoupper(Functions::flattenSingleValue($field));
49
        $fieldNames = array_map('strtoupper', array_shift($database));
50
51
        if (is_numeric($field)) {
52
            $keys = array_keys($fieldNames);
53
54
            return $keys[$field - 1];
55
        }
56
        $key = array_search($field, $fieldNames);
57
58
        return ($key) ? $key : null;
59
    }
60
61
    /**
62
     * filter.
63
     *
64
     * Parses the selection criteria, extracts the database rows that match those criteria, and
65
     * returns that subset of rows.
66
     *
67
     * @param    mixed[]        $database        The range of cells that makes up the list or database.
68
     *                                        A database is a list of related data in which rows of related
69
     *                                        information are records, and columns of data are fields. The
70
     *                                        first row of the list contains labels for each column.
71
     * @param    mixed[]        $criteria        The range of cells that contains the conditions you specify.
72
     *                                        You can use any range for the criteria argument, as long as it
73
     *                                        includes at least one column label and at least one cell below
74
     *                                        the column label in which you specify a condition for the
75
     *                                        column.
76
     *
77
     * @return    array of mixed
78
     */
79
    private static function filter($database, $criteria)
80
    {
81
        $fieldNames = array_shift($database);
82
        $criteriaNames = array_shift($criteria);
83
84
        //    Convert the criteria into a set of AND/OR conditions with [:placeholders]
85
        $testConditions = $testValues = [];
0 ignored issues
show
Unused Code introduced by
$testValues is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
86
        $testConditionsCount = 0;
87
        foreach ($criteriaNames as $key => $criteriaName) {
88
            $testCondition = [];
89
            $testConditionCount = 0;
90
            foreach ($criteria as $row => $criterion) {
91
                if ($criterion[$key] > '') {
92
                    $testCondition[] = '[:' . $criteriaName . ']' . Functions::ifCondition($criterion[$key]);
93
                    ++$testConditionCount;
94
                }
95
            }
96
            if ($testConditionCount > 1) {
97
                $testConditions[] = 'OR(' . implode(',', $testCondition) . ')';
98
                ++$testConditionsCount;
99
            } elseif ($testConditionCount == 1) {
100
                $testConditions[] = $testCondition[0];
101
                ++$testConditionsCount;
102
            }
103
        }
104
105
        if ($testConditionsCount > 1) {
106
            $testConditionSet = 'AND(' . implode(',', $testConditions) . ')';
107
        } elseif ($testConditionsCount == 1) {
108
            $testConditionSet = $testConditions[0];
109
        }
110
111
        //    Loop through each row of the database
112
        foreach ($database as $dataRow => $dataValues) {
113
            //    Substitute actual values from the database row for our [:placeholders]
114
            $testConditionList = $testConditionSet;
0 ignored issues
show
Bug introduced by
The variable $testConditionSet does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
115
            foreach ($criteriaNames as $key => $criteriaName) {
116
                $k = array_search($criteriaName, $fieldNames);
117
                if (isset($dataValues[$k])) {
118
                    $dataValue = $dataValues[$k];
119
                    $dataValue = (is_string($dataValue)) ? \PhpOffice\PhpSpreadsheet\Calculation::wrapResult(strtoupper($dataValue)) : $dataValue;
120
                    $testConditionList = str_replace('[:' . $criteriaName . ']', $dataValue, $testConditionList);
121
                }
122
            }
123
            //    evaluate the criteria against the row data
124
            $result = \PhpOffice\PhpSpreadsheet\Calculation::getInstance()->_calculateFormulaValue('=' . $testConditionList);
125
            //    If the row failed to meet the criteria, remove it from the database
126
            if (!$result) {
127
                unset($database[$dataRow]);
128
            }
129
        }
130
131
        return $database;
132
    }
133
134
    private static function getFilteredColumn($database, $field, $criteria)
135
    {
136
        //    reduce the database to a set of rows that match all the criteria
137
        $database = self::filter($database, $criteria);
138
        //    extract an array of values for the requested column
139
        $colData = [];
140
        foreach ($database as $row) {
141
            $colData[] = $row[$field];
142
        }
143
144
        return $colData;
145
    }
146
147
    /**
148
     * DAVERAGE.
149
     *
150
     * Averages the values in a column of a list or database that match conditions you specify.
151
     *
152
     * Excel Function:
153
     *        DAVERAGE(database,field,criteria)
154
     *
155
     * @category Database Functions
156
     *
157
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
158
     *                                        A database is a list of related data in which rows of related
159
     *                                        information are records, and columns of data are fields. The
160
     *                                        first row of the list contains labels for each column.
161
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
162
     *                                        column label enclosed between double quotation marks, such as
163
     *                                        "Age" or "Yield," or a number (without quotation marks) that
164
     *                                        represents the position of the column within the list: 1 for
165
     *                                        the first column, 2 for the second column, and so on.
166
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
167
     *                                        You can use any range for the criteria argument, as long as it
168
     *                                        includes at least one column label and at least one cell below
169
     *                                        the column label in which you specify a condition for the
170
     *                                        column.
171
     *
172
     * @return    float
173
     */
174
    public static function DAVERAGE($database, $field, $criteria)
175
    {
176
        $field = self::fieldExtract($database, $field);
177
        if (is_null($field)) {
178
            return null;
179
        }
180
181
        // Return
182
        return Statistical::AVERAGE(
183
            self::getFilteredColumn($database, $field, $criteria)
184
        );
185
    }
186
187
    /**
188
     * DCOUNT.
189
     *
190
     * Counts the cells that contain numbers in a column of a list or database that match conditions
191
     * that you specify.
192
     *
193
     * Excel Function:
194
     *        DCOUNT(database,[field],criteria)
195
     *
196
     * Excel Function:
197
     *        DAVERAGE(database,field,criteria)
198
     *
199
     * @category Database Functions
200
     *
201
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
202
     *                                        A database is a list of related data in which rows of related
203
     *                                        information are records, and columns of data are fields. The
204
     *                                        first row of the list contains labels for each column.
205
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
206
     *                                        column label enclosed between double quotation marks, such as
207
     *                                        "Age" or "Yield," or a number (without quotation marks) that
208
     *                                        represents the position of the column within the list: 1 for
209
     *                                        the first column, 2 for the second column, and so on.
210
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
211
     *                                        You can use any range for the criteria argument, as long as it
212
     *                                        includes at least one column label and at least one cell below
213
     *                                        the column label in which you specify a condition for the
214
     *                                        column.
215
     *
216
     * @return    int
217
     *
218
     * @TODO    The field argument is optional. If field is omitted, DCOUNT counts all records in the
219
     *            database that match the criteria.
220
     */
221 View Code Duplication
    public static function DCOUNT($database, $field, $criteria)
0 ignored issues
show
Duplication introduced by
This method 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...
222
    {
223
        $field = self::fieldExtract($database, $field);
224
        if (is_null($field)) {
225
            return null;
226
        }
227
228
        // Return
229
        return Statistical::COUNT(
230
            self::getFilteredColumn($database, $field, $criteria)
231
        );
232
    }
233
234
    /**
235
     * DCOUNTA.
236
     *
237
     * Counts the nonblank cells in a column of a list or database that match conditions that you specify.
238
     *
239
     * Excel Function:
240
     *        DCOUNTA(database,[field],criteria)
241
     *
242
     * @category Database Functions
243
     *
244
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
245
     *                                        A database is a list of related data in which rows of related
246
     *                                        information are records, and columns of data are fields. The
247
     *                                        first row of the list contains labels for each column.
248
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
249
     *                                        column label enclosed between double quotation marks, such as
250
     *                                        "Age" or "Yield," or a number (without quotation marks) that
251
     *                                        represents the position of the column within the list: 1 for
252
     *                                        the first column, 2 for the second column, and so on.
253
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
254
     *                                        You can use any range for the criteria argument, as long as it
255
     *                                        includes at least one column label and at least one cell below
256
     *                                        the column label in which you specify a condition for the
257
     *                                        column.
258
     *
259
     * @return    int
260
     *
261
     * @TODO    The field argument is optional. If field is omitted, DCOUNTA counts all records in the
262
     *            database that match the criteria.
263
     */
264
    public static function DCOUNTA($database, $field, $criteria)
265
    {
266
        $field = self::fieldExtract($database, $field);
267
        if (is_null($field)) {
268
            return null;
269
        }
270
271
        //    reduce the database to a set of rows that match all the criteria
272
        $database = self::filter($database, $criteria);
273
        //    extract an array of values for the requested column
274
        $colData = [];
275
        foreach ($database as $row) {
276
            $colData[] = $row[$field];
277
        }
278
279
        // Return
280
        return Statistical::COUNTA(
281
            self::getFilteredColumn($database, $field, $criteria)
282
        );
283
    }
284
285
    /**
286
     * DGET.
287
     *
288
     * Extracts a single value from a column of a list or database that matches conditions that you
289
     * specify.
290
     *
291
     * Excel Function:
292
     *        DGET(database,field,criteria)
293
     *
294
     * @category Database Functions
295
     *
296
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
297
     *                                        A database is a list of related data in which rows of related
298
     *                                        information are records, and columns of data are fields. The
299
     *                                        first row of the list contains labels for each column.
300
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
301
     *                                        column label enclosed between double quotation marks, such as
302
     *                                        "Age" or "Yield," or a number (without quotation marks) that
303
     *                                        represents the position of the column within the list: 1 for
304
     *                                        the first column, 2 for the second column, and so on.
305
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
306
     *                                        You can use any range for the criteria argument, as long as it
307
     *                                        includes at least one column label and at least one cell below
308
     *                                        the column label in which you specify a condition for the
309
     *                                        column.
310
     *
311
     * @return    mixed
312
     */
313
    public static function DGET($database, $field, $criteria)
314
    {
315
        $field = self::fieldExtract($database, $field);
316
        if (is_null($field)) {
317
            return null;
318
        }
319
320
        // Return
321
        $colData = self::getFilteredColumn($database, $field, $criteria);
322
        if (count($colData) > 1) {
323
            return Functions::NAN();
324
        }
325
326
        return $colData[0];
327
    }
328
329
    /**
330
     * DMAX.
331
     *
332
     * Returns the largest number in a column of a list or database that matches conditions you that
333
     * specify.
334
     *
335
     * Excel Function:
336
     *        DMAX(database,field,criteria)
337
     *
338
     * @category Database Functions
339
     *
340
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
341
     *                                        A database is a list of related data in which rows of related
342
     *                                        information are records, and columns of data are fields. The
343
     *                                        first row of the list contains labels for each column.
344
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
345
     *                                        column label enclosed between double quotation marks, such as
346
     *                                        "Age" or "Yield," or a number (without quotation marks) that
347
     *                                        represents the position of the column within the list: 1 for
348
     *                                        the first column, 2 for the second column, and so on.
349
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
350
     *                                        You can use any range for the criteria argument, as long as it
351
     *                                        includes at least one column label and at least one cell below
352
     *                                        the column label in which you specify a condition for the
353
     *                                        column.
354
     *
355
     * @return    float
356
     */
357 View Code Duplication
    public static function DMAX($database, $field, $criteria)
0 ignored issues
show
Duplication introduced by
This method 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...
358
    {
359
        $field = self::fieldExtract($database, $field);
360
        if (is_null($field)) {
361
            return null;
362
        }
363
364
        // Return
365
        return Statistical::MAX(
366
            self::getFilteredColumn($database, $field, $criteria)
367
        );
368
    }
369
370
    /**
371
     * DMIN.
372
     *
373
     * Returns the smallest number in a column of a list or database that matches conditions you that
374
     * specify.
375
     *
376
     * Excel Function:
377
     *        DMIN(database,field,criteria)
378
     *
379
     * @category Database Functions
380
     *
381
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
382
     *                                        A database is a list of related data in which rows of related
383
     *                                        information are records, and columns of data are fields. The
384
     *                                        first row of the list contains labels for each column.
385
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
386
     *                                        column label enclosed between double quotation marks, such as
387
     *                                        "Age" or "Yield," or a number (without quotation marks) that
388
     *                                        represents the position of the column within the list: 1 for
389
     *                                        the first column, 2 for the second column, and so on.
390
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
391
     *                                        You can use any range for the criteria argument, as long as it
392
     *                                        includes at least one column label and at least one cell below
393
     *                                        the column label in which you specify a condition for the
394
     *                                        column.
395
     *
396
     * @return    float
397
     */
398 View Code Duplication
    public static function DMIN($database, $field, $criteria)
0 ignored issues
show
Duplication introduced by
This method 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...
399
    {
400
        $field = self::fieldExtract($database, $field);
401
        if (is_null($field)) {
402
            return null;
403
        }
404
405
        // Return
406
        return Statistical::MIN(
407
            self::getFilteredColumn($database, $field, $criteria)
408
        );
409
    }
410
411
    /**
412
     * DPRODUCT.
413
     *
414
     * Multiplies the values in a column of a list or database that match conditions that you specify.
415
     *
416
     * Excel Function:
417
     *        DPRODUCT(database,field,criteria)
418
     *
419
     * @category Database Functions
420
     *
421
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
422
     *                                        A database is a list of related data in which rows of related
423
     *                                        information are records, and columns of data are fields. The
424
     *                                        first row of the list contains labels for each column.
425
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
426
     *                                        column label enclosed between double quotation marks, such as
427
     *                                        "Age" or "Yield," or a number (without quotation marks) that
428
     *                                        represents the position of the column within the list: 1 for
429
     *                                        the first column, 2 for the second column, and so on.
430
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
431
     *                                        You can use any range for the criteria argument, as long as it
432
     *                                        includes at least one column label and at least one cell below
433
     *                                        the column label in which you specify a condition for the
434
     *                                        column.
435
     *
436
     * @return    float
437
     */
438 View Code Duplication
    public static function DPRODUCT($database, $field, $criteria)
0 ignored issues
show
Duplication introduced by
This method 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...
439
    {
440
        $field = self::fieldExtract($database, $field);
441
        if (is_null($field)) {
442
            return null;
443
        }
444
445
        // Return
446
        return MathTrig::PRODUCT(
447
            self::getFilteredColumn($database, $field, $criteria)
448
        );
449
    }
450
451
    /**
452
     * DSTDEV.
453
     *
454
     * Estimates the standard deviation of a population based on a sample by using the numbers in a
455
     * column of a list or database that match conditions that you specify.
456
     *
457
     * Excel Function:
458
     *        DSTDEV(database,field,criteria)
459
     *
460
     * @category Database Functions
461
     *
462
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
463
     *                                        A database is a list of related data in which rows of related
464
     *                                        information are records, and columns of data are fields. The
465
     *                                        first row of the list contains labels for each column.
466
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
467
     *                                        column label enclosed between double quotation marks, such as
468
     *                                        "Age" or "Yield," or a number (without quotation marks) that
469
     *                                        represents the position of the column within the list: 1 for
470
     *                                        the first column, 2 for the second column, and so on.
471
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
472
     *                                        You can use any range for the criteria argument, as long as it
473
     *                                        includes at least one column label and at least one cell below
474
     *                                        the column label in which you specify a condition for the
475
     *                                        column.
476
     *
477
     * @return    float
478
     */
479
    public static function DSTDEV($database, $field, $criteria)
480
    {
481
        $field = self::fieldExtract($database, $field);
482
        if (is_null($field)) {
483
            return null;
484
        }
485
486
        // Return
487
        return Statistical::STDEV(
488
            self::getFilteredColumn($database, $field, $criteria)
489
        );
490
    }
491
492
    /**
493
     * DSTDEVP.
494
     *
495
     * Calculates the standard deviation of a population based on the entire population by using the
496
     * numbers in a column of a list or database that match conditions that you specify.
497
     *
498
     * Excel Function:
499
     *        DSTDEVP(database,field,criteria)
500
     *
501
     * @category Database Functions
502
     *
503
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
504
     *                                        A database is a list of related data in which rows of related
505
     *                                        information are records, and columns of data are fields. The
506
     *                                        first row of the list contains labels for each column.
507
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
508
     *                                        column label enclosed between double quotation marks, such as
509
     *                                        "Age" or "Yield," or a number (without quotation marks) that
510
     *                                        represents the position of the column within the list: 1 for
511
     *                                        the first column, 2 for the second column, and so on.
512
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
513
     *                                        You can use any range for the criteria argument, as long as it
514
     *                                        includes at least one column label and at least one cell below
515
     *                                        the column label in which you specify a condition for the
516
     *                                        column.
517
     *
518
     * @return    float
519
     */
520
    public static function DSTDEVP($database, $field, $criteria)
521
    {
522
        $field = self::fieldExtract($database, $field);
523
        if (is_null($field)) {
524
            return null;
525
        }
526
527
        // Return
528
        return Statistical::STDEVP(
529
            self::getFilteredColumn($database, $field, $criteria)
530
        );
531
    }
532
533
    /**
534
     * DSUM.
535
     *
536
     * Adds the numbers in a column of a list or database that match conditions that you specify.
537
     *
538
     * Excel Function:
539
     *        DSUM(database,field,criteria)
540
     *
541
     * @category Database Functions
542
     *
543
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
544
     *                                        A database is a list of related data in which rows of related
545
     *                                        information are records, and columns of data are fields. The
546
     *                                        first row of the list contains labels for each column.
547
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
548
     *                                        column label enclosed between double quotation marks, such as
549
     *                                        "Age" or "Yield," or a number (without quotation marks) that
550
     *                                        represents the position of the column within the list: 1 for
551
     *                                        the first column, 2 for the second column, and so on.
552
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
553
     *                                        You can use any range for the criteria argument, as long as it
554
     *                                        includes at least one column label and at least one cell below
555
     *                                        the column label in which you specify a condition for the
556
     *                                        column.
557
     *
558
     * @return    float
559
     */
560 View Code Duplication
    public static function DSUM($database, $field, $criteria)
0 ignored issues
show
Duplication introduced by
This method 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...
561
    {
562
        $field = self::fieldExtract($database, $field);
563
        if (is_null($field)) {
564
            return null;
565
        }
566
567
        // Return
568
        return MathTrig::SUM(
569
            self::getFilteredColumn($database, $field, $criteria)
570
        );
571
    }
572
573
    /**
574
     * DVAR.
575
     *
576
     * Estimates the variance of a population based on a sample by using the numbers in a column
577
     * of a list or database that match conditions that you specify.
578
     *
579
     * Excel Function:
580
     *        DVAR(database,field,criteria)
581
     *
582
     * @category Database Functions
583
     *
584
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
585
     *                                        A database is a list of related data in which rows of related
586
     *                                        information are records, and columns of data are fields. The
587
     *                                        first row of the list contains labels for each column.
588
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
589
     *                                        column label enclosed between double quotation marks, such as
590
     *                                        "Age" or "Yield," or a number (without quotation marks) that
591
     *                                        represents the position of the column within the list: 1 for
592
     *                                        the first column, 2 for the second column, and so on.
593
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
594
     *                                        You can use any range for the criteria argument, as long as it
595
     *                                        includes at least one column label and at least one cell below
596
     *                                        the column label in which you specify a condition for the
597
     *                                        column.
598
     *
599
     * @return    float
600
     */
601
    public static function DVAR($database, $field, $criteria)
602
    {
603
        $field = self::fieldExtract($database, $field);
604
        if (is_null($field)) {
605
            return null;
606
        }
607
608
        // Return
609
        return Statistical::VARFunc(
610
            self::getFilteredColumn($database, $field, $criteria)
611
        );
612
    }
613
614
    /**
615
     * DVARP.
616
     *
617
     * Calculates the variance of a population based on the entire population by using the numbers
618
     * in a column of a list or database that match conditions that you specify.
619
     *
620
     * Excel Function:
621
     *        DVARP(database,field,criteria)
622
     *
623
     * @category Database Functions
624
     *
625
     * @param    mixed[]            $database    The range of cells that makes up the list or database.
626
     *                                        A database is a list of related data in which rows of related
627
     *                                        information are records, and columns of data are fields. The
628
     *                                        first row of the list contains labels for each column.
629
     * @param    string|int    $field        Indicates which column is used in the function. Enter the
630
     *                                        column label enclosed between double quotation marks, such as
631
     *                                        "Age" or "Yield," or a number (without quotation marks) that
632
     *                                        represents the position of the column within the list: 1 for
633
     *                                        the first column, 2 for the second column, and so on.
634
     * @param    mixed[]            $criteria    The range of cells that contains the conditions you specify.
635
     *                                        You can use any range for the criteria argument, as long as it
636
     *                                        includes at least one column label and at least one cell below
637
     *                                        the column label in which you specify a condition for the
638
     *                                        column.
639
     *
640
     * @return    float
641
     */
642 View Code Duplication
    public static function DVARP($database, $field, $criteria)
0 ignored issues
show
Duplication introduced by
This method 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...
643
    {
644
        $field = self::fieldExtract($database, $field);
645
        if (is_null($field)) {
646
            return null;
647
        }
648
649
        // Return
650
        return Statistical::VARP(
651
            self::getFilteredColumn($database, $field, $criteria)
652
        );
653
    }
654
}
655