Passed
Push — master ( ac5b96...b01a48 )
by Mark
08:23
created

Maximum   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 70
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0
wmc 16

2 Methods

Rating   Name   Duplication   Size   Complexity  
B max() 0 20 7
B maxA() 0 21 9
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Calculation\Statistical;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
7
class Maximum extends MaxMinBase
8
{
9
    /**
10
     * MAX.
11
     *
12
     * MAX returns the value of the element of the values passed that has the highest value,
13
     *        with negative numbers considered smaller than positive numbers.
14
     *
15
     * Excel Function:
16
     *        MAX(value1[,value2[, ...]])
17
     *
18
     * @param mixed ...$args Data values
19
     *
20
     * @return float
21
     */
22 17
    public static function max(...$args)
23
    {
24 17
        $returnValue = null;
25
26
        // Loop through arguments
27 17
        $aArgs = Functions::flattenArray($args);
28 17
        foreach ($aArgs as $arg) {
29
            // Is it a numeric value?
30 17
            if ((is_numeric($arg)) && (!is_string($arg))) {
31 16
                if (($returnValue === null) || ($arg > $returnValue)) {
32 16
                    $returnValue = $arg;
33
                }
34
            }
35
        }
36
37 17
        if ($returnValue === null) {
38 1
            return 0;
39
        }
40
41 16
        return $returnValue;
42
    }
43
44
    /**
45
     * MAXA.
46
     *
47
     * Returns the greatest value in a list of arguments, including numbers, text, and logical values
48
     *
49
     * Excel Function:
50
     *        MAXA(value1[,value2[, ...]])
51
     *
52
     * @param mixed ...$args Data values
53
     *
54
     * @return float
55
     */
56 8
    public static function maxA(...$args)
57
    {
58 8
        $returnValue = null;
59
60
        // Loop through arguments
61 8
        $aArgs = Functions::flattenArray($args);
62 8
        foreach ($aArgs as $arg) {
63
            // Is it a numeric value?
64 8
            if ((is_numeric($arg)) || (is_bool($arg)) || ((is_string($arg) && ($arg != '')))) {
65 7
                $arg = self::datatypeAdjustmentAllowStrings($arg);
66 7
                if (($returnValue === null) || ($arg > $returnValue)) {
67 7
                    $returnValue = $arg;
68
                }
69
            }
70
        }
71
72 8
        if ($returnValue === null) {
73 1
            return 0;
74
        }
75
76 7
        return $returnValue;
77
    }
78
}
79