Skip to content

Commit d67958f

Browse files
authored
Fix scoper to clean up prefix under getRuleDefinition() method (part 5) (#8169)
1 parent 6cdd317 commit d67958f

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

scoper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static function (array $ruleDefinitionMatch) use ($prefix): string {
127127
static function (array $codeSampleMatch) use ($prefix): string {
128128
$body = str_replace($prefix . '\\', '', $codeSampleMatch[3]);
129129
$body = Strings::replace($body, '#^[ \t]*namespace ' . preg_quote($prefix, '#') . ';\R\R?#m', '');
130-
$body = Strings::replace($body, '#^[ \t]*\\\\class_alias\(.*?\);\R?#m', '');
130+
$body = Strings::replace($body, '#\R[ \t]*\\\\class_alias\(.*?\);$#', '');
131131

132132
return $codeSampleMatch[1] . $body . $codeSampleMatch[4];
133133
}

tests/Scoper/ScoperPatchersTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public function refactor(): void
102102
$this->assertStringNotContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', $codeSampleContent);
103103
$this->assertStringNotContainsString('\class_alias', $codeSampleContent);
104104
$this->assertStringContainsString('\RectorPrefix202607\ShouldStayPrefixed::run();', (string) $content);
105+
106+
foreach ($matches[1] as $codeSample) {
107+
$this->assertStringEndsNotWith("\n", $codeSample);
108+
}
105109
}
106110

107111
public function testRemovesPrefixedNamespaceInGetRuleDefinitionWithWindowsLineEndings(): void

0 commit comments

Comments
 (0)