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

SumProduct   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 41
ccs 17
cts 17
cp 1
rs 10
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B funcSumProduct() 0 29 9
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
7
class SumProduct
8
{
9
    /**
10
     * SUMPRODUCT.
11
     *
12
     * Excel Function:
13
     *        SUMPRODUCT(value1[,value2[, ...]])
14
     *
15
     * @param mixed ...$args Data values
16
     *
17
     * @return float|string The result, or a string containing an error
18
     */
19 14
    public static function funcSumProduct(...$args)
20
    {
21 14
        $arrayList = $args;
22
23 14
        $wrkArray = Functions::flattenArray(array_shift($arrayList));
24 14
        $wrkCellCount = count($wrkArray);
25
26 14
        for ($i = 0; $i < $wrkCellCount; ++$i) {
27 14
            if ((!is_numeric($wrkArray[$i])) || (is_string($wrkArray[$i]))) {
28 3
                $wrkArray[$i] = 0;
29
            }
30
        }
31
32 14
        foreach ($arrayList as $matrixData) {
33 14
            $array2 = Functions::flattenArray($matrixData);
34 14
            $count = count($array2);
35 14
            if ($wrkCellCount != $count) {
36 1
                return Functions::VALUE();
37
            }
38
39 13
            foreach ($array2 as $i => $val) {
40 13
                if ((!is_numeric($val)) || (is_string($val))) {
41 3
                    $val = 0;
42
                }
43 13
                $wrkArray[$i] *= $val;
44
            }
45
        }
46
47 13
        return array_sum($wrkArray);
48
    }
49
}
50