Skip to content

Commit 80ef63b

Browse files
thiemowmdegsherwood
authored andcommitted
Fix InlineControlStructureSniff adding brackets when there is already a bracket
While live coding, there might not only be an incomplete `if ():` at the end of a file, it might as well be an incomplete `if () {`. The most minimal example I found is `<?php if ( 1 ) { break;`. The auto-fix currently turns this into `<?php if ( 1 ) { { { { { { { { { { { { { { { { { { { { { { { { { { break;}}}}}}}}}}}}}}}}}}}}}}}}}`. 😲
1 parent 8fb3b44 commit 80ef63b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ public function process(File $phpcsFile, $stackPtr)
117117
return;
118118
}
119119

120-
if ($tokens[$nextNonEmpty]['code'] === T_COLON) {
121-
// Alternative control structure.
120+
if ($tokens[$nextNonEmpty]['code'] === T_OPEN_CURLY_BRACKET
121+
|| $tokens[$nextNonEmpty]['code'] === T_COLON
122+
) {
123+
// T_CLOSE_CURLY_BRACKET missing, or alternative control structure with
122124
// T_END... missing. Either live coding, parse error or end
123125
// tag in short open tags and scan run with short_open_tag=Off.
124126
// Bow out completely as any further detection will be unreliable

0 commit comments

Comments
 (0)