diff --git a/scoper.php b/scoper.php index 55da027ca73..6157cd59120 100644 --- a/scoper.php +++ b/scoper.php @@ -119,7 +119,7 @@ static function (string $filePath, string $prefix, string $content): string { return Strings::replace( $content, - '#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R\s*\]?\);\R\s*\})#s', + '#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R[^\r\n]*[\]\)]{2,};\R\s*\})#s', static function (array $ruleDefinitionMatch) use ($prefix): string { $ruleDefinitionContent = Strings::replace( $ruleDefinitionMatch[2], diff --git a/tests/Scoper/ScoperPatchersTest.php b/tests/Scoper/ScoperPatchersTest.php index 82830e1a53b..137f9c934d4 100644 --- a/tests/Scoper/ScoperPatchersTest.php +++ b/tests/Scoper/ScoperPatchersTest.php @@ -4,6 +4,7 @@ namespace Rector\Tests\Scoper; +use Webmozart\Assert\Assert; use Closure; use PHPUnit\Framework\TestCase; use Symfony\Component\Finder\Finder; @@ -27,13 +28,7 @@ final class AddAssertArrayFromClassMethodDocblockRector { public function getRuleDefinition(): RuleDefinition { - $metadata = 'RectorPrefix202607\Webmozart\Assert\Assert'; - - return new RuleDefinition( - 'Demo', - [ - new ConfiguredCodeSample( - <<<'CODE_SAMPLE' + return new RuleDefinition('Demo', [new ConfiguredCodeSample(<<<'CODE_SAMPLE' assertStringContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', (string) $content); $this->assertStringContainsString('use Webmozart\Assert\Assert;', $codeSampleContent); - $this->assertStringContainsString('\Webmozart\Assert\Assert::allString($items);', $codeSampleContent); - $this->assertStringContainsString("'SomeVendor\ValueObject::class'", (string) $content); - $this->assertStringContainsString('$metadata = \'Webmozart\Assert\Assert\';', (string) $content); + $this->assertStringContainsString(Assert::class . '::allString($items);', $codeSampleContent); $this->assertStringContainsString('\RectorPrefix202607\SomeVendor\Runtime::class;', (string) $content); $this->assertStringNotContainsString('namespace RectorPrefix202607;', $codeSampleContent); $this->assertStringNotContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', $codeSampleContent);