diff --git a/doc/rules/array_notation/alphabetical_array_key_sort.rst b/doc/rules/array_notation/alphabetical_array_key_sort.rst index eba1015bef7..1dc607e7f7d 100644 --- a/doc/rules/array_notation/alphabetical_array_key_sort.rst +++ b/doc/rules/array_notation/alphabetical_array_key_sort.rst @@ -23,15 +23,14 @@ Risky when the order of the array has an impact on the code execution. Configuration ------------- -``sort_special_key_mode`` -~~~~~~~~~~~~~~~~~~~~~~~~~ +``special_keys_placement`` +~~~~~~~~~~~~~~~~~~~~~~~~~~ -Whether to sort the specials keys on the bottom ``special_case_on_bottom`` or -top ``special_case_on_top``. +Whether to sort the specials keys on the bottom ``bottom`` or top ``top``. -Allowed values: ``'special_case_on_bottom'`` and ``'special_case_on_top'`` +Allowed values: ``'bottom'`` and ``'top'`` -Default value: ``'special_case_on_bottom'`` +Default value: ``'bottom'`` Examples -------- @@ -65,7 +64,7 @@ With configuration: ``[]``. Example #3 ~~~~~~~~~~ -With configuration: ``['sort_special_key_mode' => 'special_case_on_bottom']``. +With configuration: ``['special_keys_placement' => 'bottom']``. .. code-block:: diff @@ -78,7 +77,7 @@ With configuration: ``['sort_special_key_mode' => 'special_case_on_bottom']``. Example #4 ~~~~~~~~~~ -With configuration: ``['sort_special_key_mode' => 'special_case_on_top']``. +With configuration: ``['special_keys_placement' => 'top']``. .. code-block:: diff diff --git a/src/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixer.php b/src/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixer.php index 18e07aa3d6d..85bde1d1feb 100644 --- a/src/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixer.php +++ b/src/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixer.php @@ -47,11 +47,11 @@ public function getDefinition(): FixerDefinitionInterface ), new CodeSample( " '2', 'a' => '1', foo() => 'bar', 'd' => '5'];\n", - ['sort_special_key_mode' => 'special_case_on_bottom'] + ['special_keys_placement' => 'bottom'] ), new CodeSample( " '2', 'a' => '1', foo() => 'bar', 'd' => '5'];\n", - ['sort_special_key_mode' => 'special_case_on_top'] + ['special_keys_placement' => 'top'] ), ], 'Use this fixer when you want a standardised representation of your keyed arrays; it will sort the numeric and string keys of your arrays alphabetically. Special keys, like concatenated ones, are kept in the same order but are either moved to the top or bottom (default) according to the configuration option.', @@ -77,9 +77,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void protected function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ - (new FixerOptionBuilder('sort_special_key_mode', 'Whether to sort the specials keys on the bottom `special_case_on_bottom` or top `special_case_on_top`.')) - ->setAllowedValues(['special_case_on_bottom', 'special_case_on_top']) - ->setDefault('special_case_on_bottom') + (new FixerOptionBuilder('special_keys_placement', 'Whether to sort the specials keys on the bottom `bottom` or top `top`.')) + ->setAllowedValues(['bottom', 'top']) + ->setDefault('bottom') ->getOption(), ]); } @@ -166,8 +166,8 @@ protected function sortTokens(Tokens $tokens): void */ private function sortContentKeys(array $contentKeys): array { - $sortMode = $this->configuration['sort_special_key_mode']; - $specialSortDirection = ('special_case_on_top' === $sortMode) ? -1 : 1; + $specialKeysPlacement = $this->configuration['special_keys_placement']; + $specialSortDirection = ('top' === $specialKeysPlacement) ? -1 : 1; usort($contentKeys, function ($a, $b) use ($contentKeys, $specialSortDirection) { $aIsSpecial = $this->isSpecialKey($a); diff --git a/tests/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixerTest.php b/tests/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixerTest.php index bb4dcc65053..5812e2e0c4b 100644 --- a/tests/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixerTest.php +++ b/tests/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixerTest.php @@ -60,7 +60,7 @@ public static function provideFixCases(): iterable "a.*" => "int", ];', [ - 'sort_special_key_mode' => 'special_case_on_bottom', + 'special_keys_placement' => 'bottom', ], ]; @@ -84,7 +84,7 @@ public static function provideFixCases(): iterable "a.*" => "int", ];', [ - 'sort_special_key_mode' => 'special_case_on_top', + 'special_keys_placement' => 'top', ], ];