Skip to content

Commit b27f086

Browse files
committed
Merge branch 'php-8.0/squiz-controlstructurespacing-support-match' of https://github.com/jrfnl/PHP_CodeSniffer
2 parents 6836945 + a1bee01 commit b27f086

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Standards/Squiz/Sniffs/WhiteSpace/ControlStructureSpacingSniff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function register()
4646
T_TRY,
4747
T_CATCH,
4848
T_FINALLY,
49+
T_MATCH,
4950
];
5051

5152
}//end register()
@@ -232,6 +233,16 @@ public function process(File $phpcsFile, $stackPtr)
232233
}//end if
233234
}//end if
234235

236+
if ($tokens[$stackPtr]['code'] === T_MATCH) {
237+
// Move the scope closer to the semicolon/comma.
238+
$next = $phpcsFile->findNext(Tokens::$emptyTokens, ($scopeCloser + 1), null, true);
239+
if ($next !== false
240+
&& ($tokens[$next]['code'] === T_SEMICOLON || $tokens[$next]['code'] === T_COMMA)
241+
) {
242+
$scopeCloser = $next;
243+
}
244+
}
245+
235246
$trailingContent = $phpcsFile->findNext(
236247
T_WHITESPACE,
237248
($scopeCloser + 1),

src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,3 +251,13 @@ echo 'hi';
251251
?>
252252
<?php endforeach; ?>
253253
<?php endforeach; ?>
254+
255+
<?php
256+
257+
$expr = match( $foo ){
258+
259+
1 => 1,
260+
2 => 2,
261+
262+
};
263+
echo $expr;

src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.inc.fixed

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,12 @@ echo 'hi';
244244
?>
245245
<?php endforeach; ?>
246246
<?php endforeach; ?>
247+
248+
<?php
249+
250+
$expr = match($foo){
251+
1 => 1,
252+
2 => 2,
253+
};
254+
255+
echo $expr;

src/Standards/Squiz/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ public function getErrorList($testFile='ControlStructureSpacingUnitTest.inc')
5757
242 => 1,
5858
246 => 1,
5959
248 => 1,
60+
257 => 3,
61+
261 => 1,
62+
262 => 1,
6063
];
6164
break;
6265
case 'ControlStructureSpacingUnitTest.js':

0 commit comments

Comments
 (0)