Following code:
public function exists(): bool
{
$order = $someQueryBuilder->getQuery()->getOneOrNullResult();
return $order ? true : false;
}
will be "fixed" into:
public function exists(): bool
{
$order = $someQueryBuilder->getQuery()->getOneOrNullResult();
return $order;
}
...which actually breaks the code. This sniff now relies on that the condition is boolean, which may not be true. It should fix only those, where it is boolean for sure (e.g. $order !== null comparison is used).
It鈥檚 not possible with PHPCS.
Yes it is. You just fix only those where there is a comparison or boolean operator in condition.
return $order ? true : false; - not fixablereturn $order->isValid() ? true : false; - not fixablereturn $order === null ? true : false; - fixablereturn $order->getPrice() > 0 ? true : false; - fixablereturn $order || $oldOrder ? true : false; - fixableI want the second example to be fixable.
Then it should be in readme that it may break code and it is implemented that way intentionally.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Yes it is. You just fix only those where there is a comparison or boolean operator in condition.
return $order ? true : false;- not fixablereturn $order->isValid() ? true : false;- not fixablereturn $order === null ? true : false;- fixablereturn $order->getPrice() > 0 ? true : false;- fixablereturn $order || $oldOrder ? true : false;- fixable