Skip to content

Use Type->isInteger() over $dimType instanceof ConstantIntegerType #4161

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

Closed
wants to merge 1 commit into from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jul 26, 2025

No description provided.

@staabm staabm marked this pull request as ready for review July 26, 2025 09:46
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@@ -4238,7 +4238,7 @@ public function specifyExpressionType(Expr $expr, Type $type, Type $nativeType,
new ObjectType(ArrayAccess::class),
new NullType(),
];
if ($dimType instanceof ConstantIntegerType) {
if ($dimType->isInteger()->yes()) {
Copy link
Contributor Author

@staabm staabm Jul 26, 2025

Choose a reason for hiding this comment

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

$dimType instance ConstantIntegerType is already narrowed in the outer if

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Hey, this change isn't really valuable. With the original code it's obvious what's going on. We just want the if to be executed only when the left part of BooleanOr is true.

It'd also be nice to change the line with $dimType instanceof ConstantIntegerType || $dimType instanceof ConstantStringType. I understand that it might be difficult, in that case feel free to close the PR.

@staabm staabm closed this Jul 26, 2025
@staabm staabm deleted the clean-sc branch July 26, 2025 21:02
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.

3 participants