UselessParentheses currently removes parentheses around really simple expressions, but also for all conditions in ternary expressions. Since these conditions can be more complex (multiple lines, function calls, multiple epressions joined with operators etc.) it can be much less readable without the parentheses (although they are technically still not needed).
So I think there should be an option to evaluate these as useful leaving only single "simple" expressions as useless and probably also considering these expressions with unary operators (such as !) useless as well.
Fo example:
($foo) // still useless
(!$foo) // still useless
($foo && $bar) // useful
($foo !== $bar) // useful
(of course inplace of $foo and $bar would be more complicated expressions generally)
One could argue that if your ternary expressions are so complicated that you need parentheses to make them readable, you should probably refactor them into something more readable (e.g. simple method calls that actually tell you what the check is about).
It does not need to be necessary complex as in difficult to understand, but also "visually" complex, which can be even a function call with multiple parameters. Extracting it into a variable or method etc. is always possible, but sometimes not really practical and from readability point of view can make things even worse.
Other case that parentheses might be useful:
($foo['bar'] ?? false) ? true : false
I consider usefull parenthesis in instanceof case.
$abc !== null && !($abc instanceof SomeClass)
Parentheses with exclamation mark are not mark as useless.
I consider usefull parenthesis in instanceof case.
I disagree, those are useless.
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
One could argue that if your ternary expressions are so complicated that you need parentheses to make them readable, you should probably refactor them into something more readable (e.g. simple method calls that actually tell you what the check is about).