From 6180c68aaf66534781efbadac910bab57e551cf3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 18:55:26 +0700 Subject: [PATCH 1/8] Fix scoper to clean up prefix under getRuleDefinition() method (part 4) --- scoper.php | 2 +- tests/Scoper/ScoperPatchersTest.php | 23 +++-------------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/scoper.php b/scoper.php index 55da027ca73..a903d934f45 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\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..5c7ebdb25a6 100644 --- a/tests/Scoper/ScoperPatchersTest.php +++ b/tests/Scoper/ScoperPatchersTest.php @@ -27,13 +27,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('\RectorPrefix202607\SomeVendor\Runtime::class;', (string) $content); $this->assertStringNotContainsString('namespace RectorPrefix202607;', $codeSampleContent); $this->assertStringNotContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', $codeSampleContent); From c311c2c114e5d4816ce0a876d767ef74fe09452e Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 18:57:13 +0700 Subject: [PATCH 2/8] update regex --- scoper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scoper.php b/scoper.php index a903d934f45..32508c1c175 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*\})#s', + '#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R\s*\}\R\R\s*public function )#s', static function (array $ruleDefinitionMatch) use ($prefix): string { $ruleDefinitionContent = Strings::replace( $ruleDefinitionMatch[2], From e494695c57426f8f8806d6372a72880b271b0e3d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 18:58:00 +0700 Subject: [PATCH 3/8] update regex --- scoper.php | 2 +- tests/Scoper/ScoperPatchersTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/scoper.php b/scoper.php index 32508c1c175..55da027ca73 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\R\s*public function )#s', + '#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R\s*\]?\);\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 5c7ebdb25a6..84b10c5051a 100644 --- a/tests/Scoper/ScoperPatchersTest.php +++ b/tests/Scoper/ScoperPatchersTest.php @@ -129,6 +129,10 @@ public function getRuleDefinition(): RuleDefinition , ''), ]); } + + public function refactor(): void + { + } } PHP ); From 9eade58f6f715a92548ed945a8402c886b07955b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 18:58:13 +0700 Subject: [PATCH 4/8] update regex --- tests/Scoper/ScoperPatchersTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Scoper/ScoperPatchersTest.php b/tests/Scoper/ScoperPatchersTest.php index 84b10c5051a..5c7ebdb25a6 100644 --- a/tests/Scoper/ScoperPatchersTest.php +++ b/tests/Scoper/ScoperPatchersTest.php @@ -129,10 +129,6 @@ public function getRuleDefinition(): RuleDefinition , ''), ]); } - - public function refactor(): void - { - } } PHP ); From a1d5d37c898b8ada40941c0d749c838afd35a740 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 18:58:50 +0700 Subject: [PATCH 5/8] update regex --- scoper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scoper.php b/scoper.php index 55da027ca73..22f817a7e67 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\s*[\]\)]+;\R\s*\})#s', static function (array $ruleDefinitionMatch) use ($prefix): string { $ruleDefinitionContent = Strings::replace( $ruleDefinitionMatch[2], From e783624a02ce675fa24066fc285ee0ee49d71f78 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 18:59:36 +0700 Subject: [PATCH 6/8] update regex --- scoper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scoper.php b/scoper.php index 22f817a7e67..2f6fd34d651 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]*[\]\)]+;\R\s*\})#s', static function (array $ruleDefinitionMatch) use ($prefix): string { $ruleDefinitionContent = Strings::replace( $ruleDefinitionMatch[2], From b824b815c7a0a5d77172e44882a05aec04809779 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 10 Jul 2026 18:59:44 +0700 Subject: [PATCH 7/8] update regex --- scoper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scoper.php b/scoper.php index 2f6fd34d651..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[^\r\n]*[\]\)]+;\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], From 69b8b580312960bdb27512a95e076127869675eb Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Fri, 10 Jul 2026 12:00:46 +0000 Subject: [PATCH 8/8] [ci-review] Rector Rectify --- tests/Scoper/ScoperPatchersTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Scoper/ScoperPatchersTest.php b/tests/Scoper/ScoperPatchersTest.php index 5c7ebdb25a6..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; @@ -95,7 +96,7 @@ public function refactor(): void $this->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(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);