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

Narrow string on *strlen() with positive-int #3407

Merged
merged 2 commits into from
Sep 19, 2024
Merged

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Sep 6, 2024

closes phpstan/phpstan#11558

separated from #3373

&& count($exprNode->getArgs()) === 1
&& $exprNode->name instanceof Name
&& in_array(strtolower((string) $exprNode->name), ['strlen', 'mb_strlen'], true)
&& $constantType instanceof ConstantIntegerType
Copy link
Contributor Author

Choose a reason for hiding this comment

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

instead of comparison with ConstantIntegerType we now support IntegerRangeType

@@ -2192,14 +2195,11 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
}
}

if ($rightType->isInteger()->yes() || $rightType->isString()->yes()) {
if ($rightType->isString()->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.

as we no longer do ConstantIntegerType related checks in specifyTypesForConstantBinaryExpression we can simplify this loop again to what it looked like a few weeks ago.

@staabm staabm marked this pull request as ready for review September 6, 2024 06:20
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@@ -1283,7 +1283,7 @@ public function dataCondition(): iterable
),
),
[
'$foo' => 'non-empty-string',
'$foo' => "string & ~''",
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this change weird ?

Shouldn't string & ~'' be considered as non-empty-string ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its the same thing, but just a difference how the type is printed

@ondrejmirtes ondrejmirtes merged commit e629cee into phpstan:1.12.x Sep 19, 2024
477 of 499 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants