Skip to content

Commit cf41238

Browse files
committed
bug #4807 IncrementStyleFixer - handle after ")" (SpacePossum)
This PR was merged into the 2.15 branch. Discussion ---------- IncrementStyleFixer - handle after ")" Fixes #4657 Commits ------- 90bc55f IncrementStyleFixer - handle after ")"
2 parents 864ed4d + 90bc55f commit cf41238

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/Fixer/Operator/IncrementStyleFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
109109
$startIndex = $this->findStart($tokens, $index);
110110

111111
$prevToken = $tokens[$tokens->getPrevMeaningfulToken($startIndex)];
112-
if ($prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
112+
if ($prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG], ')'])) {
113113
$tokens->clearAt($index);
114114
$tokens->insertAt($startIndex, clone $token);
115115
}
116116
} elseif (self::STYLE_POST === $this->configuration['style'] && $tokensAnalyzer->isUnaryPredecessorOperator($index)) {
117117
$prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
118-
if (!$prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
118+
if (!$prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG], ')'])) {
119119
continue;
120120
}
121121

tests/Fixer/Operator/IncrementStyleFixerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ public function foo() {
173173
}
174174
}',
175175
],
176+
[
177+
'<?php if ($foo) ++$a;',
178+
'<?php if ($foo) $a++;',
179+
],
176180
];
177181
}
178182
}

0 commit comments

Comments
 (0)