-
-
Notifications
You must be signed in to change notification settings - Fork 495
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Document YodaConditionals you must (#1724)
* Document YodaConditionals you must Co-authored-by: jrfnl <[email protected]>
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |