Skip to content

Commit ee104cd

Browse files
committed
Arrays/ArrayDeclarationSpacing: replace "associative" with "keys"
Updates error messages and docblocks to use "arrays with keys" instead of "associative arrays" to align with the PHP handbook terminology. The sniff has always checked for arrays with explicit keys (whether string or numeric), not just associative arrays with string keys. This change aligns the wording with the actual behavior. The public property `allow_single_item_single_line_associative_arrays` and the error code `AssociativeArrayFound` are intentionally left unchanged to avoid breaking changes for users who reference them in their ruleset configurations. Ref: wpcs-docs 156
1 parent fa02bc4 commit ee104cd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

WordPress/Sniffs/Arrays/ArrayDeclarationSpacingSniff.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
/**
2020
* Enforces WordPress array spacing format.
2121
*
22-
* - Checks that associative arrays are multi-line.
22+
* - Checks that arrays with keys are multi-line.
2323
* - Checks that each array item in a multi-line array starts on a new line.
2424
*
2525
* @link https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/#indentation
2626
*
2727
* @since 0.11.0 - The WordPress specific additional checks have now been split off
2828
* from the `WordPress.Arrays.ArrayDeclaration` sniff into this sniff.
29-
* - Added sniffing & fixing for associative arrays.
29+
* - Added sniffing & fixing for arrays with keys.
3030
* @since 0.12.0 Decoupled this sniff from the upstream sniff completely.
3131
* This sniff now extends the WordPressCS native `Sniff` class instead.
3232
* @since 0.13.0 Added the last remaining checks from the `WordPress.Arrays.ArrayDeclaration`
3333
* sniff which were not covered elsewhere.
3434
* The `WordPress.Arrays.ArrayDeclaration` sniff has now been deprecated.
3535
* @since 0.13.0 Class name changed: this class is now namespaced.
36-
* @since 0.14.0 Single item associative arrays are now by default exempt from the
36+
* @since 0.14.0 Single item arrays with keys are now by default exempt from the
3737
* "must be multi-line" rule. This behavior can be changed using the
3838
* `allow_single_item_single_line_associative_arrays` property.
3939
* @since 3.0.0 Removed various whitespace related checks and fixers in favor of the PHPCSExtra
@@ -42,7 +42,7 @@
4242
final class ArrayDeclarationSpacingSniff extends Sniff {
4343

4444
/**
45-
* Whether or not to allow single item associative arrays to be single line.
45+
* Whether or not to allow single item arrays with keys to be single line.
4646
*
4747
* @since 0.14.0
4848
*
@@ -102,7 +102,7 @@ public function process_token( $stackPtr ) {
102102
}
103103

104104
/**
105-
* Check that associative arrays are always multi-line.
105+
* Check that arrays with keys are always multi-line.
106106
*
107107
* @since 0.13.0 The actual checks contained in this method used to
108108
* be in the `process()` method.
@@ -137,9 +137,9 @@ protected function process_single_line_array( $stackPtr, $opener, $closer ) {
137137
if ( false === $array_has_keys ) {
138138
return;
139139
}
140-
$error = 'When an array uses associative keys, each value should start on %s.';
140+
$error = 'When an array uses keys, each value should start on %s.';
141141
if ( true === $this->allow_single_item_single_line_associative_arrays ) {
142-
$error = 'When a multi-item array uses associative keys, each value should start on %s.';
142+
$error = 'When a multi-item array uses keys, each value should start on %s.';
143143
}
144144

145145
/*

0 commit comments

Comments
 (0)