Skip to content

Commit

Permalink
Document YodaConditionals you must (#1724)
Browse files Browse the repository at this point in the history
* Document YodaConditionals you must

Co-authored-by: jrfnl <[email protected]>
  • Loading branch information
Ipstenu and jrfnl authored May 16, 2022
1 parent 8ea3a0a commit 222251d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions WordPress/Docs/PHP/YodaConditionsStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<documentation title="Yoda Conditions">
<standard>
<![CDATA[
When doing logical comparisons involving variables, the variable must be placed on the right side. All constants, literals, and function calls must be placed on the left side. If neither side is a variable, the order is unimportant.
For more information:
https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#yoda-conditions
]]>
</standard>
<code_comparison>
<code title="Valid: The variable is placed on the right">
<![CDATA[
if ( <em>true === $the_force</em> ) {
$victorious = you_will( $be );
}
]]>
</code>
<code title="Invalid: The variable has been placed on the left">
<![CDATA[
if ( <em>$the_force === false</em> ) {
$victorious = you_will_not( $be );
}
]]>
</code>
</code_comparison>
</documentation>

0 comments on commit 222251d

Please sign in to comment.