use_arrow_functions.rst 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. ============================
  2. Rule ``use_arrow_functions``
  3. ============================
  4. Anonymous functions with one-liner return statement must use arrow functions.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky when using ``isset()`` on outside variables that are not imported with
  10. ``use ()``.
  11. Examples
  12. --------
  13. Example #1
  14. ~~~~~~~~~~
  15. .. code-block:: diff
  16. --- Original
  17. +++ New
  18. <?php
  19. -foo(function ($a) use ($b) {
  20. - return $a + $b;
  21. -});
  22. +foo(fn ($a) => $a + $b);
  23. Rule sets
  24. ---------
  25. The rule is part of the following rule sets:
  26. - `@PHP74Migration:risky <./../../ruleSets/PHP74MigrationRisky.rst>`_
  27. - `@PHP80Migration:risky <./../../ruleSets/PHP80MigrationRisky.rst>`_
  28. - `@PHP82Migration:risky <./../../ruleSets/PHP82MigrationRisky.rst>`_
  29. References
  30. ----------
  31. - Fixer class: `PhpCsFixer\\Fixer\\FunctionNotation\\UseArrowFunctionsFixer <./../../../src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php>`_
  32. - Test class: `PhpCsFixer\\Tests\\Fixer\\FunctionNotation\\UseArrowFunctionsFixerTest <./../../../tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php>`_
  33. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.