function_declaration.rst 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. @@ -2,13 +2,13 @@
  21. class Foo
  22. {
  23. - public static function bar ( $baz , $foo )
  24. + public static function bar($baz , $foo)
  25. {
  26. return false;
  27. }
  28. }
  29. -function foo ($bar, $baz)
  30. +function foo($bar, $baz)
  31. {
  32. return false;
  33. }
  34. Example #2
  35. ~~~~~~~~~~
  36. With configuration: ``['closure_function_spacing' => 'none']``.
  37. .. code-block:: diff
  38. --- Original
  39. +++ New
  40. @@ -1,2 +1,2 @@
  41. <?php
  42. -$f = function () {};
  43. +$f = function() {};
  44. Example #3
  45. ~~~~~~~~~~
  46. With configuration: ``['closure_function_spacing' => 'none']``.
  47. .. code-block:: diff
  48. --- Original
  49. +++ New
  50. @@ -1,2 +1,2 @@
  51. <?php
  52. -$f = fn () => null;
  53. +$f = fn() => null;
  54. Rule sets
  55. ---------
  56. The rule is part of the following rule sets:
  57. @PSR2
  58. Using the `@PSR2 <./../../ruleSets/PSR2.rst>`_ rule set will enable the ``function_declaration`` rule with the default config.
  59. @PhpCsFixer
  60. Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``function_declaration`` rule with the default config.
  61. @Symfony
  62. Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``function_declaration`` rule with the default config.