no_unneeded_control_parentheses.rst 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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']]``