function_declaration.rst 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. =============================
  2. Rule ``function_declaration``
  3. =============================
  4. Spaces should be properly placed in a function declaration.
  5. Configuration
  6. -------------
  7. ``closure_function_spacing``
  8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. Spacing to use before open parenthesis for closures.
  10. Allowed values: ``'none'``, ``'one'``
  11. Default value: ``'one'``
  12. ``trailing_comma_single_line``
  13. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. Whether trailing commas are allowed in single line signatures.
  15. Allowed types: ``bool``
  16. Default value: ``false``
  17. Examples
  18. --------
  19. Example #1
  20. ~~~~~~~~~~
  21. *Default* configuration.
  22. .. code-block:: diff
  23. --- Original
  24. +++ New
  25. <?php
  26. class Foo
  27. {
  28. - public static function bar ( $baz , $foo )
  29. + public static function bar($baz , $foo)
  30. {
  31. return false;
  32. }
  33. }
  34. -function foo ($bar, $baz)
  35. +function foo($bar, $baz)
  36. {
  37. return false;
  38. }
  39. Example #2
  40. ~~~~~~~~~~
  41. With configuration: ``['closure_function_spacing' => 'none']``.
  42. .. code-block:: diff
  43. --- Original
  44. +++ New
  45. <?php
  46. -$f = function () {};
  47. +$f = function() {};
  48. Example #3
  49. ~~~~~~~~~~
  50. With configuration: ``['closure_function_spacing' => 'none']``.
  51. .. code-block:: diff
  52. --- Original
  53. +++ New
  54. <?php
  55. -$f = fn () => null;
  56. +$f = fn() => null;
  57. Rule sets
  58. ---------
  59. The rule is part of the following rule sets:
  60. @PSR12
  61. Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``function_declaration`` rule with the default config.
  62. @PSR2
  63. Using the `@PSR2 <./../../ruleSets/PSR2.rst>`_ rule set will enable the ``function_declaration`` rule with the default config.
  64. @PhpCsFixer
  65. Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``function_declaration`` rule with the default config.
  66. @Symfony
  67. Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``function_declaration`` rule with the default config.