list_syntax.rst 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ====================
  2. Rule ``list_syntax``
  3. ====================
  4. List (``array`` destructuring) assignment should be declared using the
  5. configured syntax. Requires PHP >= 7.1.
  6. Configuration
  7. -------------
  8. ``syntax``
  9. ~~~~~~~~~~
  10. Whether to use the ``long`` or ``short`` syntax for array destructuring.
  11. Allowed values: ``'long'`` and ``'short'``
  12. Default value: ``'short'``
  13. Examples
  14. --------
  15. Example #1
  16. ~~~~~~~~~~
  17. *Default* configuration.
  18. .. code-block:: diff
  19. --- Original
  20. +++ New
  21. <?php
  22. -list($sample) = $array;
  23. +[$sample] = $array;
  24. Example #2
  25. ~~~~~~~~~~
  26. With configuration: ``['syntax' => 'long']``.
  27. .. code-block:: diff
  28. --- Original
  29. +++ New
  30. <?php
  31. -[$sample] = $array;
  32. +list($sample) = $array;
  33. Rule sets
  34. ---------
  35. The rule is part of the following rule sets:
  36. - `@PHP71Migration <./../../ruleSets/PHP71Migration.rst>`_
  37. - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_
  38. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_
  39. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_
  40. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_
  41. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_
  42. - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_
  43. - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_
  44. References
  45. ----------
  46. - Fixer class: `PhpCsFixer\\Fixer\\ListNotation\\ListSyntaxFixer <./../../../src/Fixer/ListNotation/ListSyntaxFixer.php>`_
  47. - Test class: `PhpCsFixer\\Tests\\Fixer\\ListNotation\\ListSyntaxFixerTest <./../../../tests/Fixer/ListNotation/ListSyntaxFixerTest.php>`_
  48. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.