← All changes
|
libraries/vendor/PhpSpreadsheet/Calculation/Statistical/Conditional.php
+13
-9
3.3.4
→
3.4
View file →
| @@ -9,8 +9,9 @@ | ||
| 9 | 9 | use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Database\DSum; |
| 10 | 10 | use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException; |
| 11 | 11 | use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Functions; |
| 12 | 12 | use TablePress\PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError; |
| 13 | +use TablePress\PhpOffice\PhpSpreadsheet\Shared\StringHelper; | |
| 13 | 14 | |
| 14 | 15 | class Conditional |
| 15 | 16 | { |
| 16 | 17 | private const CONDITION_COLUMN_NAME = 'CONDITION'; |
| @@ -25,14 +26,17 @@ | ||
| 25 | 26 | * Excel Function: |
| 26 | 27 | * AVERAGEIF(range,condition[, average_range]) |
| 27 | 28 | * |
| 28 | 29 | * @param mixed $range Data values, expect array |
| 29 | - * @param null|mixed[]|string $condition the criteria that defines which cells will be checked | |
| 30 | + * @param mixed $condition the criteria that defines which cells will be checked, expect null|mixed[]|string | |
| 30 | 31 | * @param mixed $averageRange Data values |
| 31 | - * @return float|int|string|null | |
| 32 | + * @return null|int|float|string | |
| 32 | 33 | */ |
| 33 | 34 | public static function AVERAGEIF($range, $condition, $averageRange = []) |
| 34 | 35 | { |
| 36 | + if ($condition !== null && !is_array($condition)) { | |
| 37 | + $condition = StringHelper::convertToString($condition); | |
| 38 | + } | |
| 35 | 39 | if (!is_array($range) || !is_array($averageRange) || array_key_exists(0, $range) || array_key_exists(0, $averageRange)) { |
| 36 | 40 | $refError = ExcelError::REF(); |
| 37 | 41 | if (in_array($refError, [$range, $averageRange], true)) { |
| 38 | 42 | return $refError; |
| @@ -55,9 +59,9 @@ | ||
| 55 | 59 | * Excel Function: |
| 56 | 60 | * AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2, criteria2]…) |
| 57 | 61 | * |
| 58 | 62 | * @param mixed $args Pairs of Ranges and Criteria |
| 59 | - * @return float|int|string|null | |
| 63 | + * @return null|int|float|string | |
| 60 | 64 | */ |
| 61 | 65 | public static function AVERAGEIFS(...$args) |
| 62 | 66 | { |
| 63 | 67 | if (empty($args)) { |
| @@ -63,9 +67,9 @@ | ||
| 63 | 67 | if (empty($args)) { |
| 64 | 68 | return 0.0; |
| 65 | 69 | } |
| 66 | 70 | if (count($args) === 3) { |
| 67 | - return self::AVERAGEIF($args[1], $args[2], $args[0]); //* @phpstan-ignore-line | |
| 71 | + return self::AVERAGEIF($args[1], $args[2], $args[0]); | |
| 68 | 72 | } |
| 69 | 73 | foreach ($args as $arg) { |
| 70 | 74 | if (is_array($arg) && array_key_exists(0, $arg)) { |
| 71 | 75 | throw new CalcException('Must specify range of cells, not any kind of literal'); |
| @@ -87,9 +91,9 @@ | ||
| 87 | 91 | * COUNTIF(range,condition) |
| 88 | 92 | * |
| 89 | 93 | * @param mixed $range Data values, expect array |
| 90 | 94 | * @param null|mixed[]|string $condition the criteria that defines which cells will be counted |
| 91 | - * @return int|string | |
| 95 | + * @return string|int | |
| 92 | 96 | */ |
| 93 | 97 | public static function COUNTIF($range, $condition) |
| 94 | 98 | { |
| 95 | 99 | if ( |
| @@ -148,9 +152,9 @@ | ||
| 148 | 152 | * Excel Function: |
| 149 | 153 | * MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2]…) |
| 150 | 154 | * |
| 151 | 155 | * @param mixed $args Pairs of Ranges and Criteria |
| 152 | - * @return float|string|null | |
| 156 | + * @return null|float|string | |
| 153 | 157 | */ |
| 154 | 158 | public static function MAXIFS(...$args) |
| 155 | 159 | { |
| 156 | 160 | if (empty($args)) { |
| @@ -171,9 +175,9 @@ | ||
| 171 | 175 | * Excel Function: |
| 172 | 176 | * MINIFS(min_range, criteria_range1, criteria1, [criteria_range2, criteria2]…) |
| 173 | 177 | * |
| 174 | 178 | * @param mixed $args Pairs of Ranges and Criteria |
| 175 | - * @return float|string|null | |
| 179 | + * @return null|float|string | |
| 176 | 180 | */ |
| 177 | 181 | public static function MINIFS(...$args) |
| 178 | 182 | { |
| 179 | 183 | if (empty($args)) { |
| @@ -195,9 +199,9 @@ | ||
| 195 | 199 | * SUMIF(range, criteria, [sum_range]) |
| 196 | 200 | * |
| 197 | 201 | * @param mixed $range Data values, expecting array |
| 198 | 202 | * @param mixed $sumRange Data values, expecting array |
| 199 | - * @return float|string|null | |
| 203 | + * @return null|float|string | |
| 200 | 204 | * @param mixed $condition |
| 201 | 205 | */ |
| 202 | 206 | public static function SUMIF($range, $condition, $sumRange = []) |
| 203 | 207 | { |
| @@ -229,9 +233,9 @@ | ||
| 229 | 233 | * Excel Function: |
| 230 | 234 | * SUMIFS(average_range, criteria_range1, criteria1, [criteria_range2, criteria2]…) |
| 231 | 235 | * |
| 232 | 236 | * @param mixed $args Pairs of Ranges and Criteria |
| 233 | - * @return float|string|null | |
| 237 | + * @return null|float|string | |
| 234 | 238 | */ |
| 235 | 239 | public static function SUMIFS(...$args) |
| 236 | 240 | { |
| 237 | 241 | if (empty($args)) { |