@@ -1487,19 +1487,21 @@ protected function processVaribleInsideElse(File $phpcsFile, $stackPtr, $varName
1487
1487
foreach ($ allAssignmentIndices as $ index ) {
1488
1488
foreach ($ blockIndices as $ blockIndex ) {
1489
1489
$ blockToken = $ tokens [$ blockIndex ];
1490
- Helpers::debug ('looking at assignment ' , $ index , 'at block index ' , $ blockIndex , 'which is token ' , $ blockToken );
1490
+ Helpers::debug ('for variable inside else, looking at assignment ' , $ index , 'at block index ' , $ blockIndex , 'which is token ' , $ blockToken );
1491
1491
if (isset ($ blockToken ['scope_opener ' ]) && isset ($ blockToken ['scope_closer ' ])) {
1492
1492
$ scopeOpener = $ blockToken ['scope_opener ' ];
1493
1493
$ scopeCloser = $ blockToken ['scope_closer ' ];
1494
1494
} else {
1495
- // If the `if` statement has no scope, it is probably inline, which means its scope is up until the next semicolon
1496
- $ scopeOpener = $ blockIndex + 1 ;
1495
+ // If the `if` statement has no scope, it is probably inline, which
1496
+ // means its scope is from the end of the condition up until the next
1497
+ // semicolon
1498
+ $ scopeOpener = isset ($ blockToken ['parenthesis_closer ' ]) ? $ blockToken ['parenthesis_closer ' ] : $ blockIndex + 1 ;
1497
1499
$ scopeCloser = $ phpcsFile ->findNext ([T_SEMICOLON ], $ scopeOpener );
1498
1500
if (! $ scopeCloser ) {
1499
1501
throw new \Exception ("Cannot find scope for if condition block at index {$ stackPtr } while examining variable {$ varName }" );
1500
1502
}
1501
1503
}
1502
- Helpers::debug ('looking at scope ' , $ index , 'between ' , $ scopeOpener , 'and ' , $ scopeCloser );
1504
+ Helpers::debug ('for variable inside else, looking at scope ' , $ index , 'between ' , $ scopeOpener , 'and ' , $ scopeCloser );
1503
1505
if (Helpers::isIndexInsideScope ($ index , $ scopeOpener , $ scopeCloser )) {
1504
1506
$ assignmentsInsideAttachedBlocks [] = $ index ;
1505
1507
}
0 commit comments