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 2 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
23 changes: 23 additions & 0 deletions WordPress/Docs/Arrays/ArrayKeySpacingRestrictionsStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<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.
]]>
</standard>
<code_comparison>
<code title="Valid: Correct whitespace for index keys">
Mike-Hermans marked this conversation as resolved.
Show resolved Hide resolved
<![CDATA[
$post = $posts[ $post_id ];
Mike-Hermans marked this conversation as resolved.
Show resolved Hide resolved
$post = $posts[123];
$post_title = $post['post_title'];
]]>
</code>
<code title="Invalid: Incorrect spacing">
Mike-Hermans marked this conversation as resolved.
Show resolved Hide resolved
<![CDATA[
$post = $posts[$post_id];
$post = $posts[ 123 ];
$post_title = $post[ 'post_title' ];
]]>
</code>
</code_comparison>
</documentation>
29 changes: 29 additions & 0 deletions WordPress/Docs/Arrays/MultipleStatementAlignmentStandard.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<documentation title="Multiple Statement Alignment">
<standard>
<![CDATA[
There should be one space on either side of a double arrow operator used to assign a value to a key. In the case of a block of related assignments, more space may be inserted to promote readability.
Mike-Hermans marked this conversation as resolved.
Show resolved Hide resolved
]]>
</standard>
<code_comparison>
<code title="Valid: Double arrow operators aligned">
<![CDATA[
$args = array(
'cat' <em>=></em> 22,
Mike-Hermans marked this conversation as resolved.
Show resolved Hide resolved
'year' <em>=></em> $current_year,
'monthnum' <em>=></em> $current_month,
'order' <em>=></em> 'ASC',
);
]]>
</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,
'order' <em>=></em> 'ASC',
);
]]>
</code>
</code_comparison>
</documentation>