Skip to content

Commit

Permalink
feature: NoUnneededControlParenthesesFixer - Fix more cases (#6409)
Browse files Browse the repository at this point in the history
NoUnneededControlParenthesesFixer - Fix more cases
  • Loading branch information
SpacePossum authored Jul 9, 2022
1 parent d80c870 commit 75d8420
Show file tree
Hide file tree
Showing 18 changed files with 1,920 additions and 299 deletions.
2 changes: 1 addition & 1 deletion doc/list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ List of Available Rules

- | ``statements``
| List of control statements to fix.
| Allowed values: a subset of ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']``
| 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']``

Expand Down
3 changes: 3 additions & 0 deletions doc/ruleSets/PhpCsFixer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ Rules
``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']]``
- `no_null_property_initialization <./../rules/class_notation/no_null_property_initialization.rst>`_
- `no_superfluous_elseif <./../rules/control_structure/no_superfluous_elseif.rst>`_
- `no_unneeded_control_parentheses <./../rules/control_structure/no_unneeded_control_parentheses.rst>`_
config:
``['statements' => ['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``
- `no_useless_else <./../rules/control_structure/no_useless_else.rst>`_
- `no_useless_return <./../rules/return_notation/no_useless_return.rst>`_
- `operator_linebreak <./../rules/operator/operator_linebreak.rst>`_
Expand Down
2 changes: 1 addition & 1 deletion doc/ruleSets/Symfony.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Rules
- `no_trailing_comma_in_singleline_function_call <./../rules/function_notation/no_trailing_comma_in_singleline_function_call.rst>`_
- `no_unneeded_control_parentheses <./../rules/control_structure/no_unneeded_control_parentheses.rst>`_
config:
``['statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']]``
``['statements' => ['break', 'clone', 'continue', 'echo_print', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``
- `no_unneeded_curly_braces <./../rules/control_structure/no_unneeded_curly_braces.rst>`_
config:
``['namespaces' => true]``
Expand Down
13 changes: 5 additions & 8 deletions doc/rules/control_structure/no_unneeded_control_parentheses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Configuration

List of control statements to fix.

Allowed values: a subset of ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']``
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']``

Expand Down Expand Up @@ -58,14 +58,11 @@ With configuration: ``['statements' => ['break', 'continue']]``.
<?php
-while ($x) { while ($y) { break (2); } }
+while ($x) { while ($y) { break 2; } }
clone($a);
-while ($y) { continue (2); }
+while ($y) { continue 2; }
echo("foo");
print("foo");
return (1 + 2);
switch ($a) { case($x); }
yield(2);
Rule sets
---------
Expand All @@ -75,9 +72,9 @@ The rule is part of the following rule sets:
@PhpCsFixer
Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_unneeded_control_parentheses`` rule with the config below:

``['statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']]``
``['statements' => ['break', 'clone', 'continue', 'echo_print', 'negative_instanceof', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``

@Symfony
Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``no_unneeded_control_parentheses`` rule with the config below:

``['statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']]``
``['statements' => ['break', 'clone', 'continue', 'echo_print', 'others', 'return', 'switch_case', 'yield', 'yield_from']]``
2 changes: 1 addition & 1 deletion src/Console/Command/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function getDisplayableAllowedValues(FixerOptionInterface $option)

if (null !== $allowed) {
$allowed = array_filter($allowed, static function ($value): bool {
return !($value instanceof \Closure);
return !$value instanceof \Closure;
});

usort($allowed, static function ($valueA, $valueB): int {
Expand Down
Loading

0 comments on commit 75d8420

Please sign in to comment.