From 2d215dc761b063cf22544f088ad3da92300f08c6 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Wed, 22 Mar 2023 18:42:23 +0100 Subject: [PATCH] Fixes #10. Don't count string interpolation as a scope beginning --- .../Whitespace/BlankLineBeforeReturnFixer.php | 6 +++++- .../Whitespace/BlankLineBeforeReturnFixerTest.php | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Fixer/Whitespace/BlankLineBeforeReturnFixer.php b/src/Fixer/Whitespace/BlankLineBeforeReturnFixer.php index dbd1e57..92ea801 100644 --- a/src/Fixer/Whitespace/BlankLineBeforeReturnFixer.php +++ b/src/Fixer/Whitespace/BlankLineBeforeReturnFixer.php @@ -67,8 +67,12 @@ final class BlankLineBeforeReturnFixer extends AbstractFixer implements Whitespa break; } + /** @var Token $backwardToken */ $backwardToken = $tokens[$backwardIndex]; - if ($backwardToken->getContent() === '{') { + /** @var Token $nextToken */ + $nextToken = $tokens[$backwardIndex + 1]; + // Exclude string interpolation: "str {$var}" + if ($backwardToken->getContent() === '{' && !$nextToken->isGivenKind(T_VARIABLE)) { break; } diff --git a/tests/Fixer/Whitespace/BlankLineBeforeReturnFixerTest.php b/tests/Fixer/Whitespace/BlankLineBeforeReturnFixerTest.php index 6144957..f77d938 100644 --- a/tests/Fixer/Whitespace/BlankLineBeforeReturnFixerTest.php +++ b/tests/Fixer/Whitespace/BlankLineBeforeReturnFixerTest.php @@ -180,6 +180,20 @@ return $c;', } ', ]; + yield [ + '