Skip to content

Commit

Permalink
Rename config option
Browse files Browse the repository at this point in the history
  • Loading branch information
Wirone committed Dec 12, 2023
1 parent 15063df commit a8baa49
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
15 changes: 7 additions & 8 deletions doc/rules/array_notation/alphabetical_array_key_sort.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/Fixer/ArrayNotation/AlphabeticalArrayKeySortFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public function getDefinition(): FixerDefinitionInterface
),
new CodeSample(
"<?php\n\$sample = ['b' => '2', 'a' => '1', foo() => 'bar', 'd' => '5'];\n",
['sort_special_key_mode' => 'special_case_on_bottom']
['special_keys_placement' => 'bottom']
),
new CodeSample(
"<?php\n\$sample = ['b' => '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.',
Expand All @@ -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(),
]);
}
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function provideFixCases(): iterable
"a.*" => "int",
];',
[
'sort_special_key_mode' => 'special_case_on_bottom',
'special_keys_placement' => 'bottom',
],
];

Expand All @@ -84,7 +84,7 @@ public static function provideFixCases(): iterable
"a.*" => "int",
];',
[
'sort_special_key_mode' => 'special_case_on_top',
'special_keys_placement' => 'top',
],
];

Expand Down

0 comments on commit a8baa49

Please sign in to comment.