function_declaration.rst 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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'`` and ``'one'``
  11. Default value: ``'one'``
  12. ``closure_fn_spacing``
  13. ~~~~~~~~~~~~~~~~~~~~~~
  14. Spacing to use before open parenthesis for short arrow functions.
  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>`_
  66. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  67. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
  68. - `@PSR2 <./../../ruleSets/PSR2.rst>`_
  69. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  70. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  71. - `@Symfony <./../../ruleSets/Symfony.rst>`_