Skip to content

Commit a9f7049

Browse files
committed
Feat: Add LongToShorthandOperatorFixer (part of #94)
1 parent 05fe5f7 commit a9f7049

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;
@@ -310,6 +311,8 @@
310311
NoLeadingNamespaceWhitespaceFixer::class,
311312
// Binary operators should be surrounded by exactly one single space.
312313
BinaryOperatorSpacesFixer::class,
314+
// Shorthand notation for operators should be used if possible.
315+
LongToShorthandOperatorFixer::class,
313316
// There must be no space around scope resolution double colons
314317
NoSpaceAroundDoubleColonFixer::class,
315318
// 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
@@ -61,6 +61,12 @@ class Basic extends AbstractBasic implements InterfaceFromThisNamespace // Fully
6161
$baz = implode(',', ['foo', 'bar']);
6262
}
6363

64+
$i = 3;
65+
$i += 6; // LongToShorthandOperatorFixer
66+
$i *= 2; // LongToShorthandOperatorFixer
67+
$text = 'foo';
68+
$text .= 'bar'; // LongToShorthandOperatorFixer
69+
6470
// HeredocIndentationFixer
6571
$heredoc = <<<HEREDOC
6672
This is a

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

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

56+
$i = 3;
57+
$i = $i + 6; // LongToShorthandOperatorFixer
58+
$i = $i * 2; // LongToShorthandOperatorFixer
59+
$text = 'foo';
60+
$text = $text . 'bar'; // LongToShorthandOperatorFixer
61+
5662
// HeredocIndentationFixer
5763
$heredoc = <<<HEREDOC
5864
This is a

0 commit comments

Comments
 (0)