ArrayDeclaration
Ensures that arrays conform to the array coding standard.
Scope
Squiz.Arrays.ArrayDeclaration
Description
This standard covers all array declarations, regardless of the number and type of values contained within the array.
The <em>
array</em>
keyword must be lowercase.
The first array key must begin on the line after the <em>
array</em>
keyword.
All array keys must be indented to one space after the start of the <em>
array</em>
keyword. The closing parenthesis must be aligned with the start of the <em>
array</em>
keyword.
All double arrow symbols must be aligned to one space after the longest array key. Alignment must be achieved using spaces.
All array values must be followed by a comma, including the final value.
Usage
<rule ref="Squiz.Arrays.ArrayDeclaration"></rule>
Examples
Example 1
Valid: array keyword lowercase
$array = array('val1', 'val2');
Invalid: first letter capitalised
$array = Array('val1', 'val2');
Example 2
Valid: first key on second line
$array = array(
'key1' => 'value1',
'key2' => 'value2',
);
Invalid: first key on same line
$array = array('key1' => 'value1',
'key2' => 'value2',
);
Example 3
Valid: aligned correctly
$array = array(
'key1' => 'value1',
'key2' => 'value2',
);
Invalid: keys and parenthesis aligned incorrectly
$array = array(
'key1' => 'value1',
'key2' => 'value2',
);
Example 4
Valid: keys and values aligned
$array = array(
'keyTen' => 'ValueTen',
'keyTwenty' => 'ValueTwenty',
);
Invalid: alignment incorrect
$array = array(
'keyTen' => 'ValueTen',
'keyTwenty' => 'ValueTwenty',
);
Example 5
Valid: comma after each value
$array = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3',
);
Invalid: no comma after last value
$array = array(
'key1' => 'value1',
'key2' => 'value2',
'key3' => 'value3'
);