Skip to content

Conversation

@b1rdex
Copy link
Contributor

@b1rdex b1rdex commented Jan 15, 2021

This is a follow up for phpstan/phpstan#4359

-
class: PHPStan\Rules\Comparison\InsaneComparisonRule
arguments:
treatMixedAsPossibleString: %reportMaybes%
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether this should be switchable, I'd prefer always enabling it

Comment on lines 52 to 54
// if ($left_type instanceof ErrorType || $right_type instanceof ErrorType) {
// return [];
// }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I uncomment this?

@b1rdex
Copy link
Contributor Author

b1rdex commented Jan 21, 2021

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

@ondrejmirtes
Copy link
Member

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

@b1rdex
Copy link
Contributor Author

b1rdex commented May 14, 2021

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

@ondrejmirtes
Copy link
Member

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 ondrejmirtes force-pushed the master branch 2 times, most recently from efd31ce to 0471f87 Compare July 29, 2021 14:08
@ondrejmirtes ondrejmirtes force-pushed the 1.5.x branch 3 times, most recently from ddd20b4 to 95d480b Compare March 18, 2022 19:53
voku pushed a commit to voku/phpstan-rules that referenced this pull request Jul 20, 2022
@ondrejmirtes
Copy link
Member

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

@b1rdex b1rdex deleted the insane-comparison branch October 16, 2022 10:59
@b1rdex
Copy link
Contributor Author

b1rdex commented Oct 16, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants