function_declaration.rst 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. =============================
  2. Rule ``function_declaration``
  3. =============================
  4. Spaces should be properly placed in a function declaration.
  5. Configuration
  6. -------------
  7. ``closure_fn_spacing``
  8. ~~~~~~~~~~~~~~~~~~~~~~
  9. Spacing to use before open parenthesis for short arrow functions.
  10. Allowed values: ``'none'`` and ``'one'``
  11. Default value: ``'one'``
  12. ``closure_function_spacing``
  13. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. Spacing to use before open parenthesis for closures.
  15. Allowed values: ``'none'`` and ``'one'``
  16. Default value: ``'one'``
  17. ``trailing_comma_single_line``
  18. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. Whether trailing commas are allowed in single line signatures.
  20. Allowed types: ``bool``
  21. Default value: ``false``
  22. Examples
  23. --------
  24. Example #1
  25. ~~~~~~~~~~
  26. *Default* configuration.
  27. .. code-block:: diff
  28. --- Original
  29. +++ New
  30. <?php
  31. class Foo
  32. {
  33. - public static function bar ( $baz , $foo )
  34. + public static function bar($baz , $foo)
  35. {
  36. return false;
  37. }
  38. }
  39. -function foo ($bar, $baz)
  40. +function foo($bar, $baz)
  41. {
  42. return false;
  43. }
  44. Example #2
  45. ~~~~~~~~~~
  46. With configuration: ``['closure_function_spacing' => 'none']``.
  47. .. code-block:: diff
  48. --- Original
  49. +++ New
  50. <?php
  51. -$f = function () {};
  52. +$f = function() {};
  53. Example #3
  54. ~~~~~~~~~~
  55. With configuration: ``['closure_fn_spacing' => 'none']``.
  56. .. code-block:: diff
  57. --- Original
  58. +++ New
  59. <?php
  60. -$f = fn () => null;
  61. +$f = fn() => null;
  62. Rule sets
  63. ---------
  64. The rule is part of the following rule sets:
  65. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  66. ``['closure_fn_spacing' => 'none']``
  67. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
  68. ``['closure_fn_spacing' => 'none']``
  69. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  70. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  71. ``['closure_fn_spacing' => 'none']``
  72. - `@PSR2 <./../../ruleSets/PSR2.rst>`_
  73. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  74. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  75. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  76. References
  77. ----------
  78. - Fixer class: `PhpCsFixer\\Fixer\\FunctionNotation\\FunctionDeclarationFixer <./../../../src/Fixer/FunctionNotation/FunctionDeclarationFixer.php>`_
  79. - Test class: `PhpCsFixer\\Tests\\Fixer\\FunctionNotation\\FunctionDeclarationFixerTest <./../../../tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php>`_
  80. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.