Passed
Push — master ( c380b2...9239b3 )
by Adrien
10:06
created

Sum::funcSumNoStrings()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 9.9666
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
7
class Sum
8
{
9
    /**
10
     * SUM, ignoring non-numeric non-error strings. This is eventually used by SUMIF.
11
     *
12
     * SUM computes the sum of all the values and cells referenced in the argument list.
13
     *
14
     * Excel Function:
15
     *        SUM(value1[,value2[, ...]])
16
     *
17
     * @param mixed ...$args Data values
18
     *
19
     * @return float|string
20
     */
21 28
    public static function funcSum(...$args)
22
    {
23 28
        $returnValue = 0;
24
25
        // Loop through the arguments
26 28
        foreach (Functions::flattenArray($args) as $arg) {
27
            // Is it a numeric value?
28 28
            if (is_numeric($arg)) {
29 27
                $returnValue += $arg;
30 4
            } elseif (Functions::isError($arg)) {
31 1
                return $arg;
32
            }
33
        }
34
35 27
        return $returnValue;
36
    }
37
38
    /**
39
     * SUM, returning error for non-numeric strings. This is used by Excel SUM function.
40
     *
41
     * SUM computes the sum of all the values and cells referenced in the argument list.
42
     *
43
     * Excel Function:
44
     *        SUM(value1[,value2[, ...]])
45
     *
46
     * @param mixed ...$args Data values
47
     *
48
     * @return float|string
49
     */
50 83
    public static function funcSumNoStrings(...$args)
51
    {
52 83
        $returnValue = 0;
53
54
        // Loop through the arguments
55 83
        foreach (Functions::flattenArray($args) as $arg) {
56
            // Is it a numeric value?
57 83
            if (is_numeric($arg)) {
58 81
                $returnValue += $arg;
59 24
            } elseif (Functions::isError($arg)) {
60 2
                return $arg;
61
            } else {
62 23
                return Functions::VALUE();
63
            }
64
        }
65
66 63
        return $returnValue;
67
    }
68
}
69