Properties in SimpleXMLElement may be null#76
Closed
orklah wants to merge 2 commits intophpstan:masterfrom
Closed
Conversation
…mplement behaviour for calls on BenevolentUnionTypes by overriding UnionType::unionResults
Contributor
Author
|
I couldn't run phpcbf on my windows PHP 7.4 because of deprecations and fatal errors due to an old version of squizlabs\php_codesniffer. I will check on the CI here to fix potential issues |
orklah
commented
Jan 2, 2020
| */ | ||
| protected function unionResults(callable $getResult): TrinaryLogic | ||
| { | ||
| return TrinaryLogic::maxMin(...array_map($getResult, $this->getTypes())); |
Contributor
Author
There was a problem hiding this comment.
I'm not certain maxMin was the best method to use here, but I wasn't sure what to do with the Maybe case...
Contributor
Author
|
@ondrejmirtes I think this is ready to be reviewed. Please tell me if I made something wrong or if I should implement more tests or anything! Thanks! |
0786c63 to
9395d76
Compare
dc2e229 to
1d0d3ad
Compare
f54fd5f to
eca550a
Compare
d45166a to
3526237
Compare
efd31ce to
0471f87
Compare
Member
|
Merged as: fcfcbd5 Sorry to keep you waiting! |
Contributor
Author
|
Wow! I lost hope on this one a looong time ago :D Thanks Ondrej! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
As discussed in phpstan/phpstan/issues/2784 this returns a BenevolentUnionType(SimpleXMLElement|null) on properties for SimpleXMLElement.
It then allows operations on BenevolentUnionType by overriding unionResults (the method implementing the logic for whether an operation is permitted). While UnionType allow an operation if it's allowed on every Type in the Union, BenevolenUnionType allow the operation if it's allowed on at least one Type in the Union.
I added a test on impossible-instanceof. Without the modification in SimpleXML, it returned
and with the modification, it doesn't return anything.
As you said in phpstan/phpstan/issues/2784:
I believe some functions in SimpleXMLElement should return BenevolentUnionType as well, such as SimpleXMLElement::attributes, who currently return SimpleXMLElement|null. Unfortunately, I tried modifying the type to (SimpleXMLElement|null) in FunctionMap but it doesn't seem to be resolved into a BenevolentUnionType. This could be for a future PR.