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

Array sniffs documentation (Related to #1722) #1737

Merged
merged 6 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<documentation title="Array Key Spacing Restrictions">
<standard>
<![CDATA[
When referring to array items, only include a space around the index if it is a variable or the key is concatenated.
]]>
</standard>
<code_comparison>
<code title="Valid: Correct spacing around the index keys">
<![CDATA[
$post = $posts<em>[ </em>$post_id<em> ]</em>;
$post_title = $post<em>[ </em>'concatenated' . $title<em> ]</em>;
$post = $posts<em>[ </em>HOME_PAGE<em> ]</em>;
$post = $posts<em>[</em>123<em>]</em>;
$post_title = $post<em>[</em>'post_title'<em>]</em>;
]]>
</code>
<code title="Invalid: Incorrect spacing around the index keys">
<![CDATA[
$post = $posts<em>[</em>$post_id<em>]</em>;
$post_title = $post<em>[</em>'concatenated' . $title<em> ]</em>;
$post = $posts<em>[</em>HOME_PAGE<em>]</em>;
$post = $posts<em>[ </em>123<em> ]</em>;
$post_title = $post<em>[ </em>'post_title'<em> ]</em>;
]]>
</code>
</code_comparison>
</documentation>
46 changes: 46 additions & 0 deletions WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<documentation title="Multiple Statement Alignment">
<standard>
<![CDATA[
When declaring arrays, there should be one space on either side of a double arrow operator used to assign a value to a key.
]]>
</standard>
<code_comparison>
<code title="Valid: correct spacing between the key and value.">
<![CDATA[
$foo = array( 'cat'<em> => </em>22 );
$bar = array( 'year'<em> => </em>$current_year );
]]>
</code>
<code title="Invalid: No or incorrect spacing between the key and value.">
<![CDATA[
$foo = array( 'cat'<em>=></em>22 );
$bar = array( 'year'<em>=> </em>$current_year );
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
In the case of a block of related assignments, it is recommended to align the arrows to promote readability.
]]>
</standard>
<code_comparison>
<code title="Valid: Double arrow operators aligned">
<![CDATA[
$args = array(
'cat'<em> => </em>22,
'year'<em> => </em>$current_year,
'monthnum'<em> => </em>$current_month,
);
]]>
</code>
<code title="Invalid: Not aligned; harder to read">
<![CDATA[
$args = array(
'cat' <em>=></em> 22,
'year' <em>=></em> $current_year,
'monthnum' <em>=></em> $current_month,
);
]]>
</code>
</code_comparison>
</documentation>