phpstan / phpstan-strict-rules

Extra strict and opinionated rules for PHPStan
MIT License
592 stars 46 forks source link

Relaxed booleansInConditions to allow 0, 1? #221

Closed Alkarex closed 1 year ago

Alkarex commented 1 year ago

Hello, While the booleansInConditions rule is nice in many situations, it does not work so elegantly with functions returning near-booleans { 0, 1 }. A salient example is preg_match():

preg_match() returns 1 if the pattern matches given subject, 0 if it does not, or false on failure.

Would you have a suggestion to relax booleansInConditions to { false, true, 0, 1} with the current code-base? If not, would you welcome a PR to allow this possibility? (And if so, hints welcome)

ondrejmirtes commented 1 year ago

I disagree. It returns 0|1|false, and you should be interested in the difference between 0 and false.

ondrejmirtes commented 1 year ago

You can always disable this rule in phpstan-strict-rules, and write your own :)

Alkarex commented 1 year ago

You can always disable this rule in phpstan-strict-rules, and write your own

That is not answering the question, but then I am guessing that you are not interested in a PR to add a rule to check for "relaxed booleans in conditions". Let me know otherwise.

ondrejmirtes commented 1 year ago

I am guessing that you are not interested in a PR to add a rule

No, I'm not, I have a different opinion.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.