Skip to content

Commit

Permalink
Feat: Add NoUnneededControlParenthesesFixer fixer (part of #94)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 23, 2024
1 parent e94dc5d commit eb1479e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"friendsofphp/php-cs-fixer": "^3.47.1",
"slevomat/coding-standard": "^8.6",
"squizlabs/php_codesniffer": "^3.9",
"symplify/easy-coding-standard": "^12.1.5"
"symplify/easy-coding-standard": "^12.1.9"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.42.0",
Expand Down
6 changes: 6 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer;
use PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer;
use PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer;
use PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer;
use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer;
use PhpCsFixer\Fixer\ControlStructure\SwitchContinueToBreakFixer;
use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer;
Expand Down Expand Up @@ -566,6 +567,11 @@
FunctionDeclarationFixer::class,
['closure_fn_spacing' => 'none'], // Defined in PER 2.0
)
// Removes unneeded parentheses around specified control statements.
->withConfiguredRule(
NoUnneededControlParenthesesFixer::class,
['statements' => ['break', 'clone', 'continue', 'echo_print', 'others', 'switch_case', 'yield', 'yield_from']],
)
// Multi-line arrays, arguments list and parameters list must have a trailing comma
->withConfiguredRule(
TrailingCommaInMultilineFixer::class,
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/Fixtures/Basic.correct.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
$text = 'foo';
$text .= 'bar'; // LongToShorthandOperatorFixer

switch ($i) {
case 1: // NoUnneededControlParenthesesFixer
$i++;
break;
default:
break;
}

// HeredocIndentationFixer
$heredoc = <<<HEREDOC
This is a
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/Fixtures/Basic.wrong.php.inc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt
$text = 'foo';
$text = $text . 'bar'; // LongToShorthandOperatorFixer

switch ($i) {
case (1): // NoUnneededControlParenthesesFixer
$i++;
break;
default:
break;
}

// HeredocIndentationFixer
$heredoc = <<<HEREDOC
This is a
Expand Down

0 comments on commit eb1479e

Please sign in to comment.