no_unneeded_control_parentheses.rst 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ========================================
  2. Rule ``no_unneeded_control_parentheses``
  3. ========================================
  4. Removes unneeded parentheses around control statements.
  5. Configuration
  6. -------------
  7. ``statements``
  8. ~~~~~~~~~~~~~~
  9. List of control statements to fix.
  10. Allowed values: a subset of ``['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']``
  11. Default value: ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield']``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. -while ($x) { while ($y) { break (2); } }
  22. -clone($a);
  23. -while ($y) { continue (2); }
  24. -echo("foo");
  25. -print("foo");
  26. -return (1 + 2);
  27. -switch ($a) { case($x); }
  28. -yield(2);
  29. +while ($x) { while ($y) { break 2; } }
  30. +clone $a;
  31. +while ($y) { continue 2; }
  32. +echo "foo";
  33. +print "foo";
  34. +return 1 + 2;
  35. +switch ($a) { case $x; }
  36. +yield 2;
  37. Example #2
  38. ~~~~~~~~~~
  39. With configuration: ``['statements' => ['break', 'continue']]``.
  40. .. code-block:: diff
  41. --- Original
  42. +++ New
  43. <?php
  44. -while ($x) { while ($y) { break (2); } }
  45. +while ($x) { while ($y) { break 2; } }
  46. clone($a);
  47. -while ($y) { continue (2); }
  48. +while ($y) { continue 2; }
  49. Rule sets
  50. ---------
  51. The rule is part of the following rule sets:
  52. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  53. ``['statements' => ['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``
  54. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  55. ``['statements' => ['break', 'clone', 'continue', 'echo_print', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``
  56. References
  57. ----------
  58. - Fixer class: `PhpCsFixer\\Fixer\\ControlStructure\\NoUnneededControlParenthesesFixer <./../../../src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php>`_
  59. - Test class: `PhpCsFixer\\Tests\\Fixer\\ControlStructure\\NoUnneededControlParenthesesFixerTest <./../../../tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php>`_
  60. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.