[wp-trac] [WordPress Trac] #42885: Fix PHPCS "Yoda Condition checks" for root files of WordPress Core.

WordPress Trac noreply at wordpress.org
Tue Dec 19 11:08:31 UTC 2017


#42885: Fix PHPCS "Yoda Condition checks" for root files of WordPress Core.
------------------------------+-------------------------------
 Reporter:  chetan200891      |       Owner:
     Type:  defect (bug)      |      Status:  new
 Priority:  normal            |   Milestone:  5.0
Component:  General           |     Version:
 Severity:  normal            |  Resolution:
 Keywords:  has-patch commit  |     Focuses:  coding-standards
------------------------------+-------------------------------

Comment (by GaryJ):

 We don't know how many instances of assignments in conditions there are
 that would need to be fixed.

 Why not:
 - merge the current patch, if it reduces violations of the current rules -
 lets at least get consistency with ''something'', even if that is later
 dropped.
 - fix up assignments in conditions (it should generally make code more
 readable anyway).
 - turn assignment in conditions check on either at the core
 phpcs.xml.dist, or `WordPress-Core` + Handbook or both).
 - discuss the relevance/redundancy of Yoda conditions now the other work
 is done.

 Personally, I don't have trouble reading A == B or B == A, but if we're
 forcing harder readability for some, for the sake of avoiding possible
 bugs, maybe that's not a good thing. IDEs can usually do assignment in
 condition inspections, even if not part of the PHPCS ruleset.

 Maybe some devs prefer Yoda conditions + having assignments in conditions?

 Maybe a handy separate repo would have a sniff that could detect
 conditions written as Yoda, so devs could run it to find all the places
 where they may want to change back to not-Yoda (if the Yoda rule is
 dropped from the Handbook)?

 Until we get to that stage though, I see no reason this shouldn't be
 committed.

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


More information about the wp-trac mailing list