Repository navigation
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.
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.
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
ondrejmirtes
left a comment
There was a problem hiding this comment.
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
fcda140 to
07916c7
Compare
On PHP 8.1+, a float operand of % (or a numeric string that may be a float) loses precision when it is converted to int, which PHP reports as deprecated. Amp-Thread-ID: https://ampcode.com/threads/T-01a19219-3b71-70b4-9e7a-3291211fe45f
07916c7 to
9bbc3d2
Compare
|
Thank you! |
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
%ModCloses phpstan/phpstan#11886