[wp-trac] [WordPress Trac] #58948: Use Elvis operator (`:?`) to replace repeating ternary patterns (`a ? a : b`)

WordPress Trac noreply at wordpress.org
Mon Jul 31 20:24:12 UTC 2023


#58948: Use Elvis operator (`:?`) to replace repeating ternary patterns (`a ? a :
b`)
-------------------------+-------------------------------
 Reporter:  ayeshrajans  |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Awaiting Review
Component:  General      |     Version:  trunk
 Severity:  trivial      |  Resolution:
 Keywords:  has-patch    |     Focuses:  coding-standards
-------------------------+-------------------------------

Comment (by jrf):

 Replying to [comment:2 ayeshrajans]:
 > I wasn't aware of this before, but it looks like wpcs disallows Elvis
 operator at the moment. I will read the issues/PRs in
 https://github.com/WordPress/WordPress-Coding-Standards to see if there is
 a good reason for it, or try see if we get them allowed. PHPCS task fails
 otherwise.

 Just checking if something is "truthy" (while used a LOT in WP), is
 generally speaking not the best of practices and as soon as a check is
 made more specific - `isset( $a ) && is_int( $a ) && $a > 10` - a short
 ternary will break.

 That's why it is forbidden and there is no intention to change this rule.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58948#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list