Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SUMIF when having different length of arrays provided as input #873

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix a SUMIF warning with some versions of PHP when having different l…
…ength of arrays provided as input
  • Loading branch information
frantzmiccoli committed Feb 1, 2019
commit 2aaa296a24c27a12b502a35b6b01f8fc9b2d066c
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com)
and this project adheres to [Semantic Versioning](https://semver.org).

## Pending

* Fix a SUMIF warning with some versions of PHP when having different length of arrays provided as input

## [1.6.0] - 2019-01-02

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/PhpSpreadsheet/Calculation/MathTrig.php
Original file line number Diff line number Diff line change
Expand Up @@ -1224,8 +1224,9 @@ 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];
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]
]
]
];