Skip to content

Commit

Permalink
Fix a SUMIF warning when having different length of arrays provided a…
Browse files Browse the repository at this point in the history
…s input

Closes PHPOffice#873
  • Loading branch information
frantzmiccoli authored and guillaume-ro-fr committed Jun 12, 2019
1 parent 2b6d76b commit 8a40a05
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Fixed

- Whitelist `tsv` extension when opening CSV files [#429](https://github.com/PHPOffice/PhpSpreadsheet/issues/429)
- Fix a SUMIF warning with some versions of PHP when having different length of arrays provided as input [#873](https://github.com/PHPOffice/PhpSpreadsheet/pull/873)

## [1.7.0] - 2019-05-26

Expand Down
5 changes: 3 additions & 2 deletions src/PhpSpreadsheet/Calculation/MathTrig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,11 +1224,12 @@ public static function SUMIF($aArgs, $condition, $sumArgs = [])
}

$testCondition = '=' . $arg . $condition;
$sumValue = array_key_exists($key, $sumArgs) ? $sumArgs[$key] : 0;

if (is_numeric($sumArgs[$key]) &&
if (is_numeric($sumValue) &&
Calculation::getInstance()->_calculateFormulaValue($testCondition)) {
// Is it a value within our criteria and only numeric can be added to the result
$returnValue += $sumArgs[$key];
$returnValue += $sumValue;
}
}

Expand Down
26 changes: 26 additions & 0 deletions tests/data/Calculation/MathTrig/SUMIF.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,30 @@
[1],
],
],
[
3,
[
[1],
[0],
[1]
],
1,
[
[3],
[4] // less elements in sum array
]
],
[
3,
[
[1],
[0] // less elements in condition array
],
1,
[
[3],
[4],
[5]
]
]
];

0 comments on commit 8a40a05

Please sign in to comment.