Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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