diff --git a/src/PhpCs/FiveLab/Sniffs/Formatting/ThrowSniff.php b/src/PhpCs/FiveLab/Sniffs/Formatting/ThrowSniff.php index e119501..a73be2c 100644 --- a/src/PhpCs/FiveLab/Sniffs/Formatting/ThrowSniff.php +++ b/src/PhpCs/FiveLab/Sniffs/Formatting/ThrowSniff.php @@ -45,7 +45,7 @@ public function process(File $phpcsFile, mixed $stackPtr): void $prevToken = $phpcsFile->getTokens()[$prevTokenPtr]; $diffLinesBefore = PhpCsUtils::getDiffLines($phpcsFile, (int) $prevTokenPtr, $stackPtr); - $possiblePrevTokens = [T_OPEN_CURLY_BRACKET, T_COLON, T_COALESCE, T_MATCH_ARROW, T_INLINE_ELSE]; + $possiblePrevTokens = [T_OPEN_CURLY_BRACKET, T_COLON, T_COALESCE, T_MATCH_ARROW, T_INLINE_ELSE, T_FN_ARROW]; if (!\in_array($prevToken['code'], $possiblePrevTokens, true) && $diffLinesBefore < 2) { $phpcsFile->addError( diff --git a/tests/PhpCs/FiveLab/Sniffs/Formatting/Resources/throw/success.php b/tests/PhpCs/FiveLab/Sniffs/Formatting/Resources/throw/success.php index 18db938..4371f1f 100644 --- a/tests/PhpCs/FiveLab/Sniffs/Formatting/Resources/throw/success.php +++ b/tests/PhpCs/FiveLab/Sniffs/Formatting/Resources/throw/success.php @@ -57,3 +57,8 @@ function withMatch(): void { default => throw new \RuntimeException('foo') }; } + +function withFn(): void +{ + $executor->shouldExecute(static fn() => throw $error); +}