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

Multinomial   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 32
ccs 13
cts 13
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A funcMultinomial() 0 21 3
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
4
5
use Exception;
6
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7
8
class Multinomial
9
{
10
    /**
11
     * MULTINOMIAL.
12
     *
13
     * Returns the ratio of the factorial of a sum of values to the product of factorials.
14
     *
15
     * @param mixed[] $args An array of mixed values for the Data Series
16
     *
17
     * @return float|string The result, or a string containing an error
18
     */
19 8
    public static function funcMultinomial(...$args)
20
    {
21 8
        $summer = 0;
22 8
        $divisor = 1;
23
24
        try {
25
            // Loop through arguments
26 8
            foreach (Functions::flattenArray($args) as $argx) {
27 8
                $arg = Helpers::validateNumericNullSubstitution($argx, null);
28 8
                Helpers::validateNotNegative($arg);
29 8
                $arg = (int) $arg;
30 8
                $summer += $arg;
31 8
                $divisor *= Fact::funcFact($arg);
32
            }
33 4
        } catch (Exception $e) {
34 4
            return $e->getMessage();
35
        }
36
37 4
        $summer = Fact::funcFact($summer);
38
39 4
        return $summer / $divisor;
40
    }
41
}
42