Skip to content

Commit 1b246d7

Browse files
committed
Feat: Add LongToShorthandOperatorFixer (part of #94)
1 parent 878bb87 commit 1b246d7

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

ecs.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
use PhpCsFixer\Fixer\NamespaceNotation\NoLeadingNamespaceWhitespaceFixer;
9494
use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer;
9595
use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer;
96+
use PhpCsFixer\Fixer\Operator\LongToShorthandOperatorFixer;
9697
use PhpCsFixer\Fixer\Operator\NewWithParenthesesFixer;
9798
use PhpCsFixer\Fixer\Operator\NoSpaceAroundDoubleColonFixer;
9899
use PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer;
@@ -311,6 +312,8 @@
311312
NoLeadingNamespaceWhitespaceFixer::class,
312313
// Binary operators should be surrounded by exactly one single space.
313314
BinaryOperatorSpacesFixer::class,
315+
// Shorthand notation for operators should be used if possible.
316+
LongToShorthandOperatorFixer::class,
314317
// There must be no space around scope resolution double colons
315318
NoSpaceAroundDoubleColonFixer::class,
316319
// All instances created with new keyword must be followed by parentheses.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
6363
$baz = implode(',', ['foo', 'bar']);
6464
}
6565

66+
$i = 3;
67+
$i += 6; // LongToShorthandOperatorFixer
68+
$i *= 2; // LongToShorthandOperatorFixer
69+
$text = 'foo';
70+
$text .= 'bar'; // LongToShorthandOperatorFixer
71+
6672
// HeredocIndentationFixer
6773
$heredoc = <<<HEREDOC
6874
This is a

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ class Basic extends \Some\Other\Namespace\AbstractBasic implements \Lmc\CodingSt
5555
$baz = join(',', ['foo', 'bar']);
5656
}
5757

58+
$i = 3;
59+
$i = $i + 6; // LongToShorthandOperatorFixer
60+
$i = $i * 2; // LongToShorthandOperatorFixer
61+
$text = 'foo';
62+
$text = $text . 'bar'; // LongToShorthandOperatorFixer
63+
5864
// HeredocIndentationFixer
5965
$heredoc = <<<HEREDOC
6066
This is a

0 commit comments

Comments
 (0)