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

Product   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 39
ccs 11
cts 11
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A funcProduct() 0 25 5
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
7
class Product
8
{
9
    /**
10
     * PRODUCT.
11
     *
12
     * PRODUCT returns the product of all the values and cells referenced in the argument list.
13
     *
14
     * Excel Function:
15
     *        PRODUCT(value1[,value2[, ...]])
16
     *
17
     * @param mixed ...$args Data values
18
     *
19
     * @return float|string
20
     */
21 20
    public static function funcProduct(...$args)
22
    {
23
        // Return value
24 20
        $returnValue = null;
25
26
        // Loop through arguments
27 20
        foreach (Functions::flattenArray($args) as $arg) {
28
            // Is it a numeric value?
29 19
            if (is_numeric($arg)) {
30 19
                if ($returnValue === null) {
31 19
                    $returnValue = $arg;
32
                } else {
33 19
                    $returnValue *= $arg;
34
                }
35
            } else {
36 1
                return Functions::VALUE();
37
            }
38
        }
39
40
        // Return
41 19
        if ($returnValue === null) {
42 1
            return 0;
43
        }
44
45 18
        return $returnValue;
46
    }
47
}
48