-
Notifications
You must be signed in to change notification settings - Fork 504
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 arrays in union based on count() with smaller/greater operator #3324
Conversation
src/Analyser/TypeSpecifier.php
Outdated
} | ||
} | ||
|
||
$result[] = $innerType; |
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.
I'd like some DRY around this, we already have the same code elsewhere. We could have a method that just accepts the narrowed array size as Type, and return SpecifiedTypes.
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.
done
src/Analyser/TypeSpecifier.php
Outdated
if ($orEqual) { | ||
$constantType = IntegerRangeType::createAllGreaterThanOrEqualTo($leftType->getValue()); | ||
} else { | ||
$constantType = IntegerRangeType::createAllGreaterThan($leftType->getValue()); |
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.
We already have this elsewhere:
$context->true() && (IntegerRangeType::createAllGreaterThanOrEqualTo(1 - $offset)->isSuperTypeOf($leftType)->yes())
|| ($context->false() && (new ConstantIntegerType(1 - $offset))->isSuperTypeOf($leftType)->yes())
Would be nice to reuse that.
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.
I don't think its the same thing. in the first block we work on the concrete constant integer, used in the comparison while in the second block we just check for the comparison value beeing >0 or >1.
This pull request has been marked as ready for review. |
Awesome, thank you! |
closes phpstan/phpstan#11480