Skip to content

Commit 6cdd317

Browse files
Fix scoper to clean up prefix under getRuleDefinition() method (part 4) (#8168)
* Fix scoper to clean up prefix under getRuleDefinition() method (part 4) * update regex * update regex * update regex * update regex * update regex * update regex * [ci-review] Rector Rectify --------- Co-authored-by: GitHub Action <actions@github.com>
1 parent 2449596 commit 6cdd317

2 files changed

Lines changed: 6 additions & 22 deletions

File tree

‎scoper.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static function (string $filePath, string $prefix, string $content): string {
119119

120120
return Strings::replace(
121121
$content,
122-
'#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R\s*\]?\);\R\s*\})#s',
122+
'#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R[^\r\n]*[\]\)]{2,};\R\s*\})#s',
123123
static function (array $ruleDefinitionMatch) use ($prefix): string {
124124
$ruleDefinitionContent = Strings::replace(
125125
$ruleDefinitionMatch[2],

‎tests/Scoper/ScoperPatchersTest.php‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\Tests\Scoper;
66

7+
use Webmozart\Assert\Assert;
78
use Closure;
89
use PHPUnit\Framework\TestCase;
910
use Symfony\Component\Finder\Finder;
@@ -27,13 +28,7 @@ final class AddAssertArrayFromClassMethodDocblockRector
2728
{
2829
public function getRuleDefinition(): RuleDefinition
2930
{
30-
$metadata = 'RectorPrefix202607\Webmozart\Assert\Assert';
31-
32-
return new RuleDefinition(
33-
'Demo',
34-
[
35-
new ConfiguredCodeSample(
36-
<<<'CODE_SAMPLE'
31+
return new RuleDefinition('Demo', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
3732
<?php
3833
3934
namespace RectorPrefix202607;
@@ -46,8 +41,7 @@ public function run()
4641
}
4742
\class_alias('SomeClass', 'SomeClass', \false);
4843
CODE_SAMPLE
49-
,
50-
<<<'CODE_SAMPLE'
44+
, <<<'CODE_SAMPLE'
5145
<?php
5246
5347
namespace RectorPrefix202607;
@@ -63,15 +57,7 @@ public function run()
6357
}
6458
\class_alias('SomeClass', 'SomeClass', \false);
6559
CODE_SAMPLE
66-
,
67-
[]
68-
),
69-
new CodeSample(
70-
'RectorPrefix202607\SomeVendor\ValueObject::class',
71-
'new RectorPrefix202607\SomeVendor\ValueObject()'
72-
),
73-
]
74-
);
60+
, [AssertClassName::WEBMOZART])]);
7561
}
7662
7763
public function refactor(): void
@@ -110,9 +96,7 @@ public function refactor(): void
11096

11197
$this->assertStringContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', (string) $content);
11298
$this->assertStringContainsString('use Webmozart\Assert\Assert;', $codeSampleContent);
113-
$this->assertStringContainsString('\Webmozart\Assert\Assert::allString($items);', $codeSampleContent);
114-
$this->assertStringContainsString("'SomeVendor\ValueObject::class'", (string) $content);
115-
$this->assertStringContainsString('$metadata = \'Webmozart\Assert\Assert\';', (string) $content);
99+
$this->assertStringContainsString(Assert::class . '::allString($items);', $codeSampleContent);
116100
$this->assertStringContainsString('\RectorPrefix202607\SomeVendor\Runtime::class;', (string) $content);
117101
$this->assertStringNotContainsString('namespace RectorPrefix202607;', $codeSampleContent);
118102
$this->assertStringNotContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', $codeSampleContent);

0 commit comments

Comments
 (0)