Skip to content

Commit

Permalink
Fix InlineControlStructureSniff adding brackets when there is already…
Browse files Browse the repository at this point in the history
… 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;}}}}}}}}}}}}}}}}}}}}}}}}}`. 😲
  • Loading branch information
thiemowmde authored Jun 17, 2020
1 parent 75ff420 commit 898d911
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ public function process(File $phpcsFile, $stackPtr)
return;
}

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

0 comments on commit 898d911

Please sign in to comment.