From a9f704915403429002bcf54c82c1f58d4ba74a25 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 b26020d..a2625d6 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; @@ -310,6 +311,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 e936f56..492fe38 100644 --- a/tests/Integration/Fixtures/Basic.correct.php.inc +++ b/tests/Integration/Fixtures/Basic.correct.php.inc @@ -61,6 +61,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 = <<