From b05f7692bbe2203ea819efbe96ffca39ae056100 Mon Sep 17 00:00:00 2001 From: javer Date: Wed, 17 Mar 2021 22:16:31 +0200 Subject: [PATCH] PHP 8.0 | Generic.CodeAnalysis.EmptyPHPStatement: add support for match --- .../Generic/Sniffs/CodeAnalysis/EmptyPHPStatementSniff.php | 2 +- .../Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc | 5 +++++ .../Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc.fixed | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyPHPStatementSniff.php b/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyPHPStatementSniff.php index a37d6cc68f..1c9e400019 100644 --- a/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyPHPStatementSniff.php +++ b/src/Standards/Generic/Sniffs/CodeAnalysis/EmptyPHPStatementSniff.php @@ -72,7 +72,7 @@ public function process(File $phpcsFile, $stackPtr) } $scopeOwner = $tokens[$tokens[$prevNonEmpty]['scope_condition']]['code']; - if ($scopeOwner === T_CLOSURE || $scopeOwner === T_ANON_CLASS) { + if ($scopeOwner === T_CLOSURE || $scopeOwner === T_ANON_CLASS || $scopeOwner === T_MATCH) { return; } diff --git a/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc b/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc index e627fd3edf..464b0e3d8c 100644 --- a/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc +++ b/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc @@ -79,3 +79,8 @@ echo $a{0}; if ($foo) { ; } + +// Do not remove semicolon after match +$c = match ($a) { + 1 => true, +}; diff --git a/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc.fixed b/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc.fixed index 2773f97b85..cc0f85e067 100644 --- a/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc.fixed +++ b/src/Standards/Generic/Tests/CodeAnalysis/EmptyPHPStatementUnitTest.inc.fixed @@ -73,3 +73,8 @@ echo $a{0}; if ($foo) { } + +// Do not remove semicolon after match +$c = match ($a) { + 1 => true, +};