Check simple conditions too
kkmuffme opened this issue · comments
These should give an error too: (and be auto-fixed if they are bool)
/** @var bool $foo */
if ( $foo ) {
if ( !$foo ) {
As this is essentially the same as:
if ( $foo == true ) {
if ( $foo == false ) {
I feel like those two things are different enough to be a separate plugin at least.
For example, I may want to forbid if($a == 2)
while accepting if($a)
.
In fact, I think this should be a feature in Psalm's core. Something like "EnforceStrictBooleanConditions" that would forbid any condition (in an if, but also in a while, for, etc...) that is not strictly a boolean.
I'll close here, but maybe open an issue on Psalm itself with this suggestion (we may already have one that looks like it IIRC)
Thanks for the feedback, I researched a bit more.
I'm not sure if this is something psalm should do natively (and neither this plugin actually), since there are phpcs rules available for this already (Squiz.Operators.ComparisonOperatorUsage has a specific sub-rule for "implicit" conditionals) - just to leave this here for anybody finding this issue on Google.