- 
  Notifications
 You must be signed in to change notification settings 
- Fork 545
Catch implicit conversions in mod operator #2466
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
Conversation
You've opened the pull request against the latest branch 1.11.x. If your code is relevant on 1.10.x and you want it to be released sooner, please rebase your pull request and change its target to 1.10.x.
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.
How the type system responds shouldn't change because it's not actually true. The % operator still returns a number but only on some PHP versions it throws a deprecation notice.
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.
So just change the rule please. The condition should be written differently.
- Please verify that all the Xfrom table here Catch implicit conversions in mod operator #2466 are reported with'Binary operation "%s" between %s and %s results in an error.'.
- Please write tests that all the Dare reported with'Deprecated in PHP 8.1: Implicit conversion from %s to %s loses precision.'.
- Please note that types can for example be int|floatormixed. You should be able to take advantage of RuleLevelHelper so that something that's always wrong likeint % floatis always reported, something that might be wrong likeint % float|intis reported on level 7 andint % mixedis reported on level 9.
Please see how RuleLevelHelper::findTypeToCheck is used in many existing rules like InvalidCastRule. Basically there's a callback that checks the type and transforms the type based on the rule level. Then there's $type instanceof ErrorType with early return and then there's the callback called again on the transformed type.
340a3ed to
 264bbb3  
 Compare
 
 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 like this much more! 👍
But the rule should report this only on 8.1+. Please add a new method in PhpVersion and ask about it in the rule.
e5e12f7 to
 02eaab3  
 Compare
 
 - modify InvalidBinaryOperationRule
fcda140 to
 07916c7  
 Compare
 
 
Uh oh!
There was an error while loading. Please reload this page.
Catch deprecated implicit type conversions that occur in PHP 8.1 and later.
The following BinaryOp that may cause deprecation.
This PR is part of phpstan/phpstan#8288 and change regarding the mod operator of #2450
※(注記)O = safe, D = deprecated, X = not safe
%Mod