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

Cover non-empty-string in substr #577

Merged
merged 26 commits into from
Jul 19, 2021
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 18, 2021

@staabm
Copy link
Contributor Author

staabm commented Jul 18, 2021

Except CS this seems good to go.

Remaing error look unrelated

@staabm staabm marked this pull request as ready for review July 18, 2021 16:03
@staabm staabm marked this pull request as draft July 18, 2021 18:15
@staabm
Copy link
Contributor Author

staabm commented Jul 18, 2021

Hmm the error is related.. need to investigate .

update: fixed

@staabm staabm marked this pull request as ready for review July 19, 2021 08:38
@staabm
Copy link
Contributor Author

staabm commented Jul 19, 2021

ready for merge


$negativeOffset = $this->getIntValue($offset) < 0;
$zeroOffset = $this->getIntValue($offset) === 0;
$positiveLength = false;
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, fixed.

Copy link
Contributor Author

@staabm staabm Jul 19, 2021

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() ?

Copy link
Member

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()

Copy link
Contributor Author

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

src/Type/Php/SubstrDynamicReturnTypeExtension.php Outdated Show resolved Hide resolved
@ondrejmirtes ondrejmirtes merged commit 9ee914b into phpstan:master Jul 19, 2021
@ondrejmirtes
Copy link
Member

Thank you!

@staabm staabm deleted the patch-2 branch July 19, 2021 14:18
mglaman pushed a commit to mglaman/phpstan-src that referenced this pull request Jul 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants