Skip to content

Commit 6180c68

Browse files
committed
Fix scoper to clean up prefix under getRuleDefinition() method (part 4)
1 parent 2449596 commit 6180c68

2 files changed

Lines changed: 4 additions & 21 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\s*\})#s',
123123
static function (array $ruleDefinitionMatch) use ($prefix): string {
124124
$ruleDefinitionContent = Strings::replace(
125125
$ruleDefinitionMatch[2],

tests/Scoper/ScoperPatchersTest.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ final class AddAssertArrayFromClassMethodDocblockRector
2727
{
2828
public function getRuleDefinition(): RuleDefinition
2929
{
30-
$metadata = 'RectorPrefix202607\Webmozart\Assert\Assert';
31-
32-
return new RuleDefinition(
33-
'Demo',
34-
[
35-
new ConfiguredCodeSample(
36-
<<<'CODE_SAMPLE'
30+
return new RuleDefinition('Demo', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
3731
<?php
3832
3933
namespace RectorPrefix202607;
@@ -46,8 +40,7 @@ public function run()
4640
}
4741
\class_alias('SomeClass', 'SomeClass', \false);
4842
CODE_SAMPLE
49-
,
50-
<<<'CODE_SAMPLE'
43+
, <<<'CODE_SAMPLE'
5144
<?php
5245
5346
namespace RectorPrefix202607;
@@ -63,15 +56,7 @@ public function run()
6356
}
6457
\class_alias('SomeClass', 'SomeClass', \false);
6558
CODE_SAMPLE
66-
,
67-
[]
68-
),
69-
new CodeSample(
70-
'RectorPrefix202607\SomeVendor\ValueObject::class',
71-
'new RectorPrefix202607\SomeVendor\ValueObject()'
72-
),
73-
]
74-
);
59+
, [AssertClassName::WEBMOZART])]);
7560
}
7661
7762
public function refactor(): void
@@ -111,8 +96,6 @@ public function refactor(): void
11196
$this->assertStringContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', (string) $content);
11297
$this->assertStringContainsString('use Webmozart\Assert\Assert;', $codeSampleContent);
11398
$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);
11699
$this->assertStringContainsString('\RectorPrefix202607\SomeVendor\Runtime::class;', (string) $content);
117100
$this->assertStringNotContainsString('namespace RectorPrefix202607;', $codeSampleContent);
118101
$this->assertStringNotContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', $codeSampleContent);

0 commit comments

Comments
 (0)