Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds rules that report a float that may be
NAN,INFor-INFreaching code that does not handle it, as proposed in phpstan/phpstan#15751. The issue has the runtime behaviour (https://3v4l.org/TPOsd) and the open points.Tiers
nonFiniteFloats, on in bleedingEdge. They report a value that is certainly non-finite, likeNAN,INF, a float narrowed byis_nan(), or an array shape with such a value in a key that is not optional.checkNonFiniteFloats(off by default) also reports a value that may be non-finite, which includes plainfloat.mixedis not reported.Rules
nonFiniteFloat.jsonEncodeJsonEncodeNonFiniteFloatRulejson_encode()and the values of arrays in itnonFiniteFloat.toStringEchoNanRule,PrintNanRule,ConcatNanRule,AssignConcatNanRule,InterpolatedStringNanRule,StringCastNanRulenonFiniteFloat.toIntIntCastNonFiniteFloatRule,IntvalNonFiniteFloatRule(int)andintval()nonFiniteFloat.formatFormatNonFiniteFloatRulenumber_format(), and the float, int and%splaceholders ofprintf(),sprintf()andfprintf()%s: 8.5+)NonFiniteFloatHelperdecides for each rule whether the float part of a value can be one of the floats it does not handle, and whether to report it.PhpVersion::warnsOnNonFiniteFloatConversion()andPhpVersions::warnsOnNonFiniteFloatConversion()gate the PHP 8.5 warnings.Testing
NonFiniteFloatRulesTestruns every rule on one file: once withoutcheckNonFiniteFloatsand once with it. The conversions to string and int are expected only on PHP 8.5+.NonFiniteFloatRulesPhp84Testruns the same file withphpVersion: 80400and expects none of them.phpVersion: 80500, the bleedingEdge tier reports nothing, andcheckNonFiniteFloatsreports 46 places.The documentation of
checkNonFiniteFloatson phpstan.org would follow once the design is settled.Closes phpstan/phpstan#15751