From 070943185ff0fb24e042a2b51532f6ab887ee570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 7 May 2024 12:02:11 +0200 Subject: [PATCH] Feat: Add LongToShorthandOperatorFixer (part of #94) --- ecs.php | 3 +++ tests/Integration/Fixtures/Basic.correct.php.inc | 6 ++++++ tests/Integration/Fixtures/Basic.wrong.php.inc | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/ecs.php b/ecs.php index 1346cb1..08ea7af 100644 --- a/ecs.php +++ b/ecs.php @@ -93,6 +93,7 @@ use PhpCsFixer\Fixer\NamespaceNotation\NoLeadingNamespaceWhitespaceFixer; use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer; use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer; +use PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer; use PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer; use PhpCsFixer\Fixer\Operator\NoSpaceAroundDoubleColonFixer; use PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer; @@ -311,6 +312,8 @@ NoLeadingNamespaceWhitespaceFixer::class, // Binary operators should be surrounded by exactly one single space. BinaryOperatorSpacesFixer::class, + // Shorthand notation for operators should be used if possible. + LongToShorthandOperatorFixer::class, // There must be no space around scope resolution double colons NoSpaceAroundDoubleColonFixer::class, // All instances created with new keyword must be followed by parentheses. diff --git a/tests/Integration/Fixtures/Basic.correct.php.inc b/tests/Integration/Fixtures/Basic.correct.php.inc index ad05bd6..19ad0be 100644 --- a/tests/Integration/Fixtures/Basic.correct.php.inc +++ b/tests/Integration/Fixtures/Basic.correct.php.inc @@ -63,6 +63,12 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully $baz = implode(',', ['foo', 'bar']); } + $i = 3; + $i += 6; // LongToShorthandOperatorFixer + $i *= 2; // LongToShorthandOperatorFixer + $text = 'foo'; + $text .= 'bar'; // LongToShorthandOperatorFixer + // HeredocIndentationFixer $heredoc = <<