基础代码

This commit is contained in:
2021-02-26 22:23:13 +08:00
parent 7884df52f0
commit a719feebba
2585 changed files with 328263 additions and 0 deletions
@@ -0,0 +1,112 @@
<documentation title="Array Indentation">
<standard>
<![CDATA[
The array closing bracket indentation should line up with the start of the content on the line containing the array opener.
]]>
</standard>
<code_comparison>
<code title="Valid: Closing bracket lined up correctly">
<![CDATA[
$args = array(
'post_id' => 22,
<em>);</em>
]]>
</code>
<code title="Invalid: Closing bracket lined up incorrectly">
<![CDATA[
$args = array(
'post_id' => 22,
<em>);</em>
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
In multi-line arrays, array items should be indented by a 4-space tab for each level of nested array, so that the array visually matches its structure.
]]>
</standard>
<code_comparison>
<code title="Valid: Correctly indented array">
<![CDATA[
$args = array(
'post_id' => 22,
'comment_count' => array(
<em>'value' => 25,
'compare' => '>=',</em>
),
'post_type' => array(
'post',
'page',
),
);
]]>
</code>
<code title="Invalid: Indented incorrectly; harder to read.">
<![CDATA[
$args = array(
'post_id' => 22,
'comment_count' => array(
<em>'value' => 25,
'compare' => '>=',</em>
),
'post_type' => array(
<em>'post',
'page',</em>
),
);
]]>
</code>
</code_comparison>
<standard>
<![CDATA[
Subsequent lines in multiline array items should be indented at least as much as the first line of the array item.
For heredocs/nowdocs, this does not apply to the content of the heredoc/nowdoc or the closer, but it does apply to the comma separating the item from the next.
]]>
</standard>
<code_comparison>
<code title="Valid: Subsequent lines are indented correctly.">
<![CDATA[
$args = array(
'phrase' => 'start of phrase'
. 'concatented additional phrase'
. 'more text',
);
]]>
</code>
<code title="Invalid: Subsequent items are indented before the first line item.">
<![CDATA[
$args = array(
'phrase' => 'start of phrase'
. 'concatented additional phrase'
. 'more text',
);
]]>
</code>
</code_comparison>
<code_comparison>
<code title="Valid: Opener and comma after closer are indented correctly">
<![CDATA[
$text = array(
<<<EOD
start of phrase
concatented additional phrase
more text
EOD
,
);
]]>
</code>
<code title="Invalid: Opener is aligned incorrectly to match the closer. The comma does not align correctly with the array indentation.">
<![CDATA[
$text = array(
<em><<<EOD</em>
start of phrase
concatented additional phrase
more text
EOD
<em>,</em>
);
]]>
</code>
</code_comparison>
</documentation>
@@ -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>
@@ -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>