Add Insane Comparison Rule
This is a follow up for https://github.com/phpstan/phpstan/discussions/4359
Hi @ondrejmirtes. Could you please take a look at this?
Hi, this code will need some work but I'm currently busy to look into this. Stay tuned!
Hi @ondrejmirtes. I'd like to finish the thing and have it merged. Any chance having this reviewed?
Hi, it'd need some more work to be able to merge this. For example I don't want the new treatMixedAsPossibleString setting. Instead, the rule should employ RuleLevelHelper which returns StrictMixedType with checkExplicitMixed: true.
RuleLevelHelper would also make sure that some errors are reported on level 5 while others (when partially wrong unions are involved) are reported on level 7.
Additionally, the error message needs improvement by saying what's wrong about the comparison.
Hi, I'm cleaning up old and stale PRs. Please send a new PR if you're still interested, thanks.
Hi @ondrejmirtes! I don't plan to reimplement this.
This rule was about https://wiki.php.net/rfc/string_to_number_comparison – breaking change in PHP 8. I think this is a good feature, but it's hard to implement it.
Personally, I think it's easier to just create a rule don't ever use a loose comparison operators if variables are of different types (or mixed) (including array_* functions and more stuff – see Proposal in the RFC) and add it to some PHPStan level.