-
Notifications
You must be signed in to change notification settings - Fork 431
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
Cover non-empty-string in substr
#577
Conversation
Except CS this seems good to go. Remaing error look unrelated |
Hmm the error is related.. need to investigate . update: fixed |
ready for merge |
|
||
$negativeOffset = $this->getIntValue($offset) < 0; | ||
$zeroOffset = $this->getIntValue($offset) === 0; | ||
$positiveLength = false; |
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.
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 positive
It also accounts for unions of ConstantIntegerType, like 1|3
.
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.
thx, fixed.
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.
does this mean I should check for a zero offset with
IntegerRangeType::fromInterval(0, 0)->isSuperTypeOf($offset)->yes()
?
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.
You can check for that with:
(new ConstantIntegerType(0))->isSuperTypeOf($offset)->yes()
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.
ConstantIntegerType, like
1|3
.
also added testcases to cover that
Thank you! |
Closes phpstan/phpstan#5324
see https://3v4l.org/aKs2O