-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Add support for IFS() logical function #1442
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
baa1792
Add support for IFS() logical function
Takitaf 89acbb9
Update IFS logical function reference on function lists
Takitaf 1c2a7e8
Use Exception as false value in IFS logical function, so it never col…
Takitaf 9e9d1c5
Merge branch 'master' of https://github.com/PHPOffice/PhpSpreadsheet
Takitaf 0061ca8
Update returning type of setUp method in IFS tests, so it is compatib…
Takitaf 0128adc
Add comment to explain use of Exception as false value in IFS logical…
Takitaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,6 +161,7 @@ HYPERLINK | |
HYPGEOMDIST | ||
IF | ||
IFERROR | ||
IFS | ||
IMABS | ||
IMAGINARY | ||
IMARGUMENT | ||
|
31 changes: 31 additions & 0 deletions
31
tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical; | ||
|
||
use PhpOffice\PhpSpreadsheet\Calculation\Functions; | ||
use PhpOffice\PhpSpreadsheet\Calculation\Logical; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class IfsTest extends TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); | ||
} | ||
|
||
/** | ||
* @dataProvider providerIFS | ||
* | ||
* @param mixed $expectedResult | ||
*/ | ||
public function testIFS($expectedResult, ...$args) | ||
{ | ||
$result = Logical::IFS(...$args); | ||
$this->assertEquals($expectedResult, $result); | ||
} | ||
|
||
public function providerIFS() | ||
{ | ||
return require 'data/Calculation/Logical/IFS.php'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
return [ | ||
[ | ||
'#N/A', | ||
], | ||
[ | ||
1, | ||
true, | ||
1, | ||
], | ||
[ | ||
'#N/A', | ||
false, | ||
1, | ||
true | ||
], | ||
[ | ||
'ABC', | ||
true, | ||
'ABC', | ||
], | ||
[ | ||
'#N/A', | ||
false, | ||
false, | ||
false, | ||
1, | ||
false, | ||
'ABC' | ||
], | ||
[ | ||
'ABC', | ||
false, | ||
false, | ||
false, | ||
1, | ||
true, | ||
'ABC' | ||
], | ||
[ | ||
false, | ||
true, | ||
false, | ||
false, | ||
1, | ||
true, | ||
'ABC' | ||
], | ||
]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand your concern that there is a possibility that the returned result may be a valid case of the string
'#Not Yet Implemented'
; unlikely, but not impossible.I might be inclined to create something purely PHP detectable, that cannot exist in a spreadsheet, such as an exception. Maybe create a new EvaluateIfFalseException which can be returned as
$result
rather than thrown; and directly type tested rather than simply value tested.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea. Can I use just simple instance of generic Exception in that case:
$falseValueException = new Exception();
? Not sure if we need special Exception for that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you could use a standard Exception, I was simply thinking about readabilityand providing a named exception where the name provided contextual meaning