diff --git a/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php b/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php index cfeb657e39..f38fd0e89b 100644 --- a/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php +++ b/src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php @@ -46,6 +46,7 @@ public function register() T_TRY, T_CATCH, T_FINALLY, + T_MATCH, ]; }//end register() @@ -232,6 +233,16 @@ public function process(File $phpcsFile, $stackPtr) }//end if }//end if + if ($tokens[$stackPtr]['code'] === T_MATCH) { + // Move the scope closer to the semicolon/comma. + $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($scopeCloser + 1), null, true); + if ($next !== false + && ($tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['code'] === T_COMMA) + ) { + $scopeCloser = $next; + } + } + $trailingContent = $phpcsFile->findNext( T_WHITESPACE, ($scopeCloser + 1), diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc index 785a4a8cc3..0371ce49b4 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc +++ b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc @@ -251,3 +251,13 @@ echo 'hi'; ?> + + 1, + 2 => 2, + +}; +echo $expr; diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed index 1674b3dbfa..ad4505c3e1 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed +++ b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed @@ -244,3 +244,12 @@ echo 'hi'; ?> + + 1, + 2 => 2, +}; + +echo $expr; diff --git a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php index eeef2b0635..ac3f5d6ff5 100644 --- a/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php +++ b/src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php @@ -57,6 +57,9 @@ public function getErrorList($testFile='ControlStructureSpacingUnitTest.inc') 242 => 1, 246 => 1, 248 => 1, + 257 => 3, + 261 => 1, + 262 => 1, ]; break; case 'ControlStructureSpacingUnitTest.js':