Skip to content

Commit be4a35e

Browse files
committed
Feat: Add NoUnneededControlParenthesesFixer fixer (part of #94)
1 parent 8ced259 commit be4a35e

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"friendsofphp/php-cs-fixer": "^3.47.1",
1515
"slevomat/coding-standard": "^8.6",
1616
"squizlabs/php_codesniffer": "^3.9",
17-
"symplify/easy-coding-standard": "^12.1.5"
17+
"symplify/easy-coding-standard": "^12.1.9"
1818
},
1919
"require-dev": {
2020
"ergebnis/composer-normalize": "^2.42.0",

ecs.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
6464
use PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer;
6565
use PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer;
66+
use PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer;
6667
use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer;
6768
use PhpCsFixer\Fixer\ControlStructure\SwitchContinueToBreakFixer;
6869
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
@@ -566,6 +567,11 @@
566567
FunctionDeclarationFixer::class,
567568
['closure_fn_spacing' => 'none'], // Defined in PER 2.0
568569
)
570+
// Removes unneeded parentheses around specified control statements.
571+
->withConfiguredRule(
572+
NoUnneededControlParenthesesFixer::class,
573+
['statements' => ['break', 'clone', 'continue', 'echo_print', 'others', 'switch_case', 'yield', 'yield_from']],
574+
)
569575
// Multi-line arrays, arguments list and parameters list must have a trailing comma
570576
->withConfiguredRule(
571577
TrailingCommaInMultilineFixer::class,

tests/Integration/Fixtures/Basic.correct.php.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
6969
$text = 'foo';
7070
$text .= 'bar'; // LongToShorthandOperatorFixer
7171

72+
switch ($i) {
73+
case 1: // NoUnneededControlParenthesesFixer
74+
$i++;
75+
break;
76+
default:
77+
break;
78+
}
79+
7280
// HeredocIndentationFixer
7381
$heredoc = <<<HEREDOC
7482
This is a

tests/Integration/Fixtures/Basic.wrong.php.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt
6161
$text = 'foo';
6262
$text = $text . 'bar'; // LongToShorthandOperatorFixer
6363

64+
switch ($i) {
65+
case (1): // NoUnneededControlParenthesesFixer
66+
$i++;
67+
break;
68+
default:
69+
break;
70+
}
71+
6472
// HeredocIndentationFixer
6573
$heredoc = <<<HEREDOC
6674
This is a

0 commit comments

Comments
 (0)