coding-standards
coding-standards copied to clipboard
Add rule to avoid redundant ternaries
I've seen in a few places we have code like this:
return $foo ? true : false;
The ternary here is redundant and is actually just casting the variable to a boolean. Using an actual cast is cleaner:
return (bool) $foo;
(The reverse is true as well, return $foo ? false : true; can be replaced with return ! $foo)
Is there a PHPCS sniff for this? @rmccue to investigate. I'm :+1: on the change proposed here
Neither PHPCS nor WP have a sniff for this.
Also nothing in the wider market :( Let's move to backlog; it's nice, but would require some custom work, so someday...