no_unneeded_braces.rst 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ===========================
  2. Rule ``no_unneeded_braces``
  3. ===========================
  4. Removes unneeded braces that are superfluous and aren't part of a control
  5. structure's body.
  6. Configuration
  7. -------------
  8. ``namespaces``
  9. ~~~~~~~~~~~~~~
  10. Remove unneeded braces from bracketed namespaces.
  11. Allowed types: ``bool``
  12. Default value: ``false``
  13. Examples
  14. --------
  15. Example #1
  16. ~~~~~~~~~~
  17. *Default* configuration.
  18. .. code-block:: diff
  19. --- Original
  20. +++ New
  21. -<?php {
  22. +<?php
  23. echo 1;
  24. -}
  25. +
  26. switch ($b) {
  27. - case 1: {
  28. + case 1:
  29. break;
  30. - }
  31. +
  32. }
  33. Example #2
  34. ~~~~~~~~~~
  35. With configuration: ``['namespaces' => true]``.
  36. .. code-block:: diff
  37. --- Original
  38. +++ New
  39. <?php
  40. -namespace Foo {
  41. +namespace Foo;
  42. function Bar(){}
  43. -}
  44. +
  45. Rule sets
  46. ---------
  47. The rule is part of the following rule sets:
  48. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  49. ``['namespaces' => true]``
  50. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  51. ``['namespaces' => true]``
  52. References
  53. ----------
  54. - Fixer class: `PhpCsFixer\\Fixer\\ControlStructure\\NoUnneededBracesFixer <./../../../src/Fixer/ControlStructure/NoUnneededBracesFixer.php>`_
  55. - Test class: `PhpCsFixer\\Tests\\Fixer\\ControlStructure\\NoUnneededBracesFixerTest <./../../../tests/Fixer/ControlStructure/NoUnneededBracesFixerTest.php>`_
  56. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.