Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rule to avoid redundant ternaries #154

Open
rmccue opened this issue Oct 16, 2019 · 3 comments
Open

Add rule to avoid redundant ternaries #154

rmccue opened this issue Oct 16, 2019 · 3 comments
Assignees
Labels

Comments

@rmccue
Copy link
Member

rmccue commented Oct 16, 2019

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)

@kadamwhite
Copy link
Contributor

Is there a PHPCS sniff for this? @rmccue to investigate. I'm 👍 on the change proposed here

@kadamwhite
Copy link
Contributor

Neither PHPCS nor WP have a sniff for this.

@rmccue
Copy link
Member Author

rmccue commented May 19, 2020

Also nothing in the wider market :( Let's move to backlog; it's nice, but would require some custom work, so someday...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants