Skip to content

Commit 4ea5d68

Browse files
committed
OperatorLinebreakFixer - fix for switch/case
1 parent e4fdb6f commit 4ea5d68

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Fixer/OperatorLinebreakFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ 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)) {
205+
$prevIndex = $tokens->getPrevTokenOfKind($prevIndex, [[T_CASE], '?']);
206+
if ($prevIndex === null || $tokens[$prevIndex]->isGivenKind(T_CASE)) {
207207
return null;
208208
}
209209
}

tests/Fixer/OperatorLinebreakFixerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,9 @@ function foo() {
305305
'<?php
306306
switch ($foo) {
307307
case 1:
308-
return true;
308+
return $isOK ? 1 : -1;
309+
case 2:
310+
return 100;
309311
}
310312
',
311313
];

0 commit comments

Comments
 (0)