Skip to content

Commit 1c714ef

Browse files
RafaelFunchalmattgaldino
authored andcommitted
Adding documentation for WordPress.Arrays.ArrayDeclarationSpacing
Co-authored-by: RafaelFunchal <RafaelFunchal@users.noreply.github.com> Co-authored-by: mattgaldino <mattgaldino@users.noreply.github.com>
1 parent f48a181 commit 1c714ef

1 file changed

Lines changed: 75 additions & 0 deletions

File tree

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0"?>
2+
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
4+
title="Array Declaration Spacing"
5+
>
6+
<standard>
7+
<![CDATA[
8+
When an array uses keys, each key/value pair must start on a new line.
9+
]]>
10+
</standard>
11+
<code_comparison>
12+
<code title="Valid: There is only one key/value pair per line.">
13+
<![CDATA[
14+
$args = array(
15+
<em>'post_id' => 22</em>,
16+
<em>'category' => 1</em>,
17+
);
18+
]]>
19+
</code>
20+
<code title="Invalid: More than one key/value pair per line.">
21+
<![CDATA[
22+
$args = array(
23+
<em>'post_id' => 22, 'category' => 1</em>,
24+
);
25+
]]>
26+
</code>
27+
</code_comparison>
28+
<standard>
29+
<![CDATA[
30+
Each item in a multi-line array must be on a new line.
31+
]]>
32+
</standard>
33+
<code_comparison>
34+
<code title="Valid: Only one array item per line.">
35+
<![CDATA[
36+
$args = array(
37+
<em>'post_id'</em>,
38+
<em>'comment_count'</em>,
39+
<em>'post_type'</em>,
40+
);
41+
]]>
42+
</code>
43+
<code title="Invalid: More than one item per line in a multi-line array.">
44+
<![CDATA[
45+
$args = array(
46+
<em>'post_id', 'comment_count', 'post_type'</em>,
47+
);
48+
]]>
49+
</code>
50+
</code_comparison>
51+
<standard>
52+
<![CDATA[
53+
Associative arrays with multiple key-value pairs must also follow this rule.
54+
]]>
55+
</standard>
56+
<code_comparison>
57+
<code title="Valid: Each key-value pair on its own line.">
58+
<![CDATA[
59+
$settings = array(
60+
<em>'width' => 300</em>,
61+
<em>'height' => 200</em>,
62+
<em>'color' => 'blue'</em>,
63+
);
64+
]]>
65+
</code>
66+
<code title="Invalid: Multiple key-value pairs on the same line in a multi-line array.">
67+
<![CDATA[
68+
$settings = array(
69+
<em>'width' => 300, 'height' => 200</em>,
70+
<em>'color' => 'blue'</em>,
71+
);
72+
]]>
73+
</code>
74+
</code_comparison>
75+
</documentation>

0 commit comments

Comments
 (0)