phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Add Insane Comparison Rule

Open b1rdex opened this issue 5 years ago • 4 comments

This is a follow up for https://github.com/phpstan/phpstan/discussions/4359

b1rdex avatar Jan 15 '21 10:01 b1rdex

Hi @ondrejmirtes. Could you please take a look at this?

b1rdex avatar Jan 21 '21 04:01 b1rdex

Hi, this code will need some work but I'm currently busy to look into this. Stay tuned!

ondrejmirtes avatar Jan 21 '21 08:01 ondrejmirtes

Hi @ondrejmirtes. I'd like to finish the thing and have it merged. Any chance having this reviewed?

b1rdex avatar May 14 '21 13:05 b1rdex

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.

ondrejmirtes avatar May 14 '21 14:05 ondrejmirtes

Hi, I'm cleaning up old and stale PRs. Please send a new PR if you're still interested, thanks.

ondrejmirtes avatar Oct 16 '22 10:10 ondrejmirtes

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.

b1rdex avatar Oct 16 '22 11:10 b1rdex