51 lines
1.6 KiB
XML
51 lines
1.6 KiB
XML
|
<?xml version="1.0"?>
|
||
|
<documentation xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||
|
xsi:noNamespaceSchemaLocation="https://phpcsstandards.github.io/PHPCSDevTools/phpcsdocs.xsd"
|
||
|
title="Array 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>
|