Skip to content

Commit e4fdb6f

Browse files
authored
OperatorLinebreakFixer - false positive change (#74)
1 parent 65b51a9 commit e4fdb6f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Fixer/OperatorLinebreakFixer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ private function getOperatorIndices(Tokens $tokens, int $index): ?array
202202
if ($tokens[$prevIndex]->getContent() === '?') {
203203
return [$prevIndex, $index];
204204
}
205+
$prevIndex = $tokens->getPrevTokenOfKind($prevIndex, [[T_SWITCH], '?']);
206+
if ($prevIndex === null || $tokens[$prevIndex]->isGivenKind(T_SWITCH)) {
207+
return null;
208+
}
205209
}
206210

207211
return [$index];

tests/Fixer/OperatorLinebreakFixerTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,15 @@ function foo() {
298298
'<?php
299299
return $foo ?/* Lorem ipsum */:
300300
$bar;
301+
',
302+
];
303+
304+
yield [
305+
'<?php
306+
switch ($foo) {
307+
case 1:
308+
return true;
309+
}
301310
',
302311
];
303312
}

0 commit comments

Comments
 (0)