Browse Source

ArraySyntaxFixer, ListSyntaxFixer - change default syntax to short

Dariusz Ruminski 4 years ago
parent
commit
856fef44e9

+ 2 - 0
UPGRADE-v3.md

@@ -83,7 +83,9 @@ Rule | Option | Change
 
 Rule | Option | Old value | New value
 ---- | ---- | ---- | ----
+`array_syntax` | `syntax` | `'long'`, `'short'`
 `function_to_constant` | `functions` | `['get_class', 'php_sapi_name', 'phpversion', 'pi']` | `['get_called_class', 'get_class', 'php_sapi_name', 'phpversion', 'pi']`
+`list_syntax` | `syntax` | `'long'`, `'short'`
 `method_argument_space` | `on_multiline` | `'ignore'` | `'ensure_fully_multiline'`
 `native_constant_invocation` | `strict` | `false` | `true`
 `native_function_casing` | `include` | `@internal` | `@compiler_optimized`

+ 0 - 2
doc/ruleSets/PHP54Migration.rst

@@ -8,5 +8,3 @@ Rules
 -----
 
 - `array_syntax <./../rules/array_notation/array_syntax.rst>`_
-  config:
-  ``['syntax' => 'short']``

+ 0 - 2
doc/ruleSets/PHP71Migration.rst

@@ -9,8 +9,6 @@ Rules
 
 - `@PHP70Migration <./PHP70Migration.rst>`_
 - `list_syntax <./../rules/list_notation/list_syntax.rst>`_
-  config:
-  ``['syntax' => 'short']``
 - `visibility_required <./../rules/class_notation/visibility_required.rst>`_
   config:
   ``['elements' => ['const', 'method', 'property']]``

+ 0 - 2
doc/ruleSets/Symfony.rst

@@ -9,8 +9,6 @@ Rules
 
 - `@PSR12 <./PSR12.rst>`_
 - `array_syntax <./../rules/array_notation/array_syntax.rst>`_
-  config:
-  ``['syntax' => 'short']``
 - `backtick_to_shell_exec <./../rules/alias/backtick_to_shell_exec.rst>`_
 - `binary_operator_spaces <./../rules/operator/binary_operator_spaces.rst>`_
 - `blank_line_before_statement <./../rules/whitespace/blank_line_before_statement.rst>`_

+ 14 - 30
doc/rules/array_notation/array_syntax.rst

@@ -14,7 +14,7 @@ Whether to use the ``long`` or ``short`` array syntax.
 
 Allowed values: ``'long'``, ``'short'``
 
-Default value: ``'long'``
+Default value: ``'short'``
 
 Examples
 --------
@@ -30,13 +30,13 @@ Example #1
    +++ New
    @@ -1,2 +1,2 @@
     <?php
-   -[1,2];
-   +array(1,2);
+   -array(1,2);
+   +[1,2];
 
 Example #2
 ~~~~~~~~~~
 
-With configuration: ``['syntax' => 'short']``.
+With configuration: ``['syntax' => 'long']``.
 
 .. code-block:: diff
 
@@ -44,8 +44,8 @@ With configuration: ``['syntax' => 'short']``.
    +++ New
    @@ -1,2 +1,2 @@
     <?php
-   -array(1,2);
-   +[1,2];
+   -[1,2];
+   +array(1,2);
 
 Rule sets
 ---------
@@ -53,41 +53,25 @@ Rule sets
 The rule is part of the following rule sets:
 
 @PHP54Migration
-  Using the `@PHP54Migration <./../../ruleSets/PHP54Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP54Migration <./../../ruleSets/PHP54Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.
 
 @PHP70Migration
-  Using the `@PHP70Migration <./../../ruleSets/PHP70Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP70Migration <./../../ruleSets/PHP70Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.
 
 @PHP71Migration
-  Using the `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.
 
 @PHP73Migration
-  Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.
 
 @PHP74Migration
-  Using the `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.
 
 @PHP80Migration
-  Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.
 
 @PhpCsFixer
-  Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.
 
 @Symfony
-  Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``array_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``array_syntax`` rule with the default config.

+ 10 - 18
doc/rules/list_notation/list_syntax.rst

@@ -15,7 +15,7 @@ Whether to use the ``long`` or ``short`` ``list`` syntax.
 
 Allowed values: ``'long'``, ``'short'``
 
-Default value: ``'long'``
+Default value: ``'short'``
 
 Examples
 --------
@@ -31,13 +31,13 @@ Example #1
    +++ New
    @@ -1,2 +1,2 @@
     <?php
-   -[$sample] = $array;
-   +list($sample) = $array;
+   -list($sample) = $array;
+   +[$sample] = $array;
 
 Example #2
 ~~~~~~~~~~
 
-With configuration: ``['syntax' => 'short']``.
+With configuration: ``['syntax' => 'long']``.
 
 .. code-block:: diff
 
@@ -45,8 +45,8 @@ With configuration: ``['syntax' => 'short']``.
    +++ New
    @@ -1,2 +1,2 @@
     <?php
-   -list($sample) = $array;
-   +[$sample] = $array;
+   -[$sample] = $array;
+   +list($sample) = $array;
 
 Rule sets
 ---------
@@ -54,21 +54,13 @@ Rule sets
 The rule is part of the following rule sets:
 
 @PHP71Migration
-  Using the `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the default config.
 
 @PHP73Migration
-  Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the default config.
 
 @PHP74Migration
-  Using the `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the default config.
 
 @PHP80Migration
-  Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the config below:
-
-  ``['syntax' => 'short']``
+  Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the default config.

+ 6 - 6
src/Fixer/ArrayNotation/ArraySyntaxFixer.php

@@ -54,13 +54,13 @@ final class ArraySyntaxFixer extends AbstractFixer implements ConfigurableFixerI
         return new FixerDefinition(
             'PHP arrays should be declared using the configured syntax.',
             [
-                new CodeSample(
-                    "<?php\n[1,2];\n"
-                ),
                 new VersionSpecificCodeSample(
                     "<?php\narray(1,2);\n",
-                    new VersionSpecification(50400),
-                    ['syntax' => 'short']
+                    new VersionSpecification(50400)
+                ),
+                new CodeSample(
+                    "<?php\n[1,2];\n",
+                    ['syntax' => 'long']
                 ),
             ]
         );
@@ -105,7 +105,7 @@ final class ArraySyntaxFixer extends AbstractFixer implements ConfigurableFixerI
         return new FixerConfigurationResolver([
             (new FixerOptionBuilder('syntax', 'Whether to use the `long` or `short` array syntax.'))
                 ->setAllowedValues(['long', 'short'])
-                ->setDefault('long') // TODO @3.0 change to short
+                ->setDefault('short')
                 ->getOption(),
         ]);
     }

+ 4 - 4
src/Fixer/ListNotation/ListSyntaxFixer.php

@@ -54,13 +54,13 @@ final class ListSyntaxFixer extends AbstractFixer implements ConfigurableFixerIn
             'List (`array` destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.',
             [
                 new VersionSpecificCodeSample(
-                    "<?php\n[\$sample] = \$array;\n",
+                    "<?php\nlist(\$sample) = \$array;\n",
                     new VersionSpecification(70100)
                 ),
                 new VersionSpecificCodeSample(
-                    "<?php\nlist(\$sample) = \$array;\n",
+                    "<?php\n[\$sample] = \$array;\n",
                     new VersionSpecification(70100),
-                    ['syntax' => 'short']
+                    ['syntax' => 'long']
                 ),
             ]
         );
@@ -108,7 +108,7 @@ final class ListSyntaxFixer extends AbstractFixer implements ConfigurableFixerIn
         return new FixerConfigurationResolver([
             (new FixerOptionBuilder('syntax', 'Whether to use the `long` or `short` `list` syntax.'))
                 ->setAllowedValues(['long', 'short'])
-                ->setDefault('long') // TODO @3.0 change to short
+                ->setDefault('short')
                 ->getOption(),
         ]);
     }

+ 1 - 1
src/RuleSet/Sets/PHP54MigrationSet.php

@@ -22,7 +22,7 @@ final class PHP54MigrationSet extends AbstractRuleSetDescription
     public function getRules()
     {
         return [
-            'array_syntax' => ['syntax' => 'short'],
+            'array_syntax' => true,
         ];
     }
 

+ 1 - 1
src/RuleSet/Sets/PHP71MigrationSet.php

@@ -23,7 +23,7 @@ final class PHP71MigrationSet extends AbstractRuleSetDescription
     {
         return [
             '@PHP70Migration' => true,
-            'list_syntax' => ['syntax' => 'short'],
+            'list_syntax' => true,
             'visibility_required' => [
                 'elements' => [
                     'const',

Some files were not shown because too many files changed in this diff