123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- ========================================
- Rule ``no_unneeded_control_parentheses``
- ========================================
- Removes unneeded parentheses around control statements.
- Configuration
- -------------
- ``statements``
- ~~~~~~~~~~~~~~
- List of control statements to fix.
- Allowed values: a subset of ``['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']``
- Default value: ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield']``
- Examples
- --------
- Example #1
- ~~~~~~~~~~
- *Default* configuration.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -while ($x) { while ($y) { break (2); } }
- -clone($a);
- -while ($y) { continue (2); }
- -echo("foo");
- -print("foo");
- -return (1 + 2);
- -switch ($a) { case($x); }
- -yield(2);
- +while ($x) { while ($y) { break 2; } }
- +clone $a;
- +while ($y) { continue 2; }
- +echo "foo";
- +print "foo";
- +return 1 + 2;
- +switch ($a) { case $x; }
- +yield 2;
- Example #2
- ~~~~~~~~~~
- With configuration: ``['statements' => ['break', 'continue']]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -while ($x) { while ($y) { break (2); } }
- +while ($x) { while ($y) { break 2; } }
- clone($a);
- -while ($y) { continue (2); }
- +while ($y) { continue 2; }
- Rule sets
- ---------
- The rule is part of the following rule sets:
- - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
- ``['statements' => ['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``
- - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
- ``['statements' => ['break', 'clone', 'continue', 'echo_print', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``
- References
- ----------
- - Fixer class: `PhpCsFixer\\Fixer\\ControlStructure\\NoUnneededControlParenthesesFixer <./../../../src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php>`_
- - Test class: `PhpCsFixer\\Tests\\Fixer\\ControlStructure\\NoUnneededControlParenthesesFixerTest <./../../../tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php>`_
- The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
|