Cover non-empty-string in substr#577
Merged
ondrejmirtes merged 26 commits intophpstan:masterfrom Jul 19, 2021
Merged
Conversation
ondrejmirtes
requested changes
Jul 18, 2021
staabm
commented
Jul 18, 2021
staabm
commented
Jul 18, 2021
Contributor
Author
|
Except CS this seems good to go. Remaing error look unrelated |
Contributor
Author
|
Hmm the error is related.. need to investigate . update: fixed |
Contributor
Author
|
ready for merge |
ondrejmirtes
requested changes
Jul 19, 2021
|
|
||
| $negativeOffset = $this->getIntValue($offset) < 0; | ||
| $zeroOffset = $this->getIntValue($offset) === 0; | ||
| $positiveLength = false; |
Member
There was a problem hiding this comment.
You should ask about whether a number is positive or negative this way:
IntegerRangeType::fromInterval(null, -1)->isSuperTypeOf($offset)->yes() // is negative
IntegerRangeType::fromInterval(1, null)->isSuperTypeOf($offset)->yes() // is positiveIt also accounts for unions of ConstantIntegerType, like 1|3.
Contributor
Author
There was a problem hiding this comment.
does this mean I should check for a zero offset with
IntegerRangeType::fromInterval(0, 0)->isSuperTypeOf($offset)->yes() ?
Member
There was a problem hiding this comment.
You can check for that with:
(new ConstantIntegerType(0))->isSuperTypeOf($offset)->yes()
Contributor
Author
There was a problem hiding this comment.
ConstantIntegerType, like
1|3.
also added testcases to cover that
Member
|
Thank you! |
mglaman
pushed a commit
to mglaman/phpstan-src
that referenced
this pull request
Jul 23, 2021
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.
Closes phpstan/phpstan#5324
see https://3v4l.org/aKs2O