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

Document YodaConditionals you must #1724

Merged
merged 4 commits into from
May 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>