From ab76bcb859866e28f177e331c93ef4d7cb2c59b8 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 19:13:14 +0700 Subject: [PATCH] Fix scoper to clean up prefix under getRuleDefinition() method (part 5) --- scoper.php | 2 +- tests/Scoper/ScoperPatchersTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scoper.php b/scoper.php index 6157cd59120..a744e529014 100644 --- a/scoper.php +++ b/scoper.php @@ -127,7 +127,7 @@ static function (array $ruleDefinitionMatch) use ($prefix): string { static function (array $codeSampleMatch) use ($prefix): string { $body = str_replace($prefix . '\\', '', $codeSampleMatch[3]); $body = Strings::replace($body, '#^[ \t]*namespace ' . preg_quote($prefix, '#') . ';\R\R?#m', ''); - $body = Strings::replace($body, '#^[ \t]*\\\\class_alias\(.*?\);\R?#m', ''); + $body = Strings::replace($body, '#\R[ \t]*\\\\class_alias\(.*?\);$#', ''); return $codeSampleMatch[1] . $body . $codeSampleMatch[4]; } diff --git a/tests/Scoper/ScoperPatchersTest.php b/tests/Scoper/ScoperPatchersTest.php index 137f9c934d4..edc9b52ae74 100644 --- a/tests/Scoper/ScoperPatchersTest.php +++ b/tests/Scoper/ScoperPatchersTest.php @@ -102,6 +102,10 @@ public function refactor(): void $this->assertStringNotContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', $codeSampleContent); $this->assertStringNotContainsString('\class_alias', $codeSampleContent); $this->assertStringContainsString('\RectorPrefix202607\ShouldStayPrefixed::run();', (string) $content); + + foreach ($matches[1] as $codeSample) { + $this->assertStringEndsNotWith("\n", $codeSample); + } } public function testRemovesPrefixedNamespaceInGetRuleDefinitionWithWindowsLineEndings(): void