Skip to content

Commit 67276ab

Browse files
authored
Fix scoper to clean up prefix under getRuleDefinition() method (part 2) (#8166)
* Fix scoper to clean up prefix under getRuleDefinition() method (part 2) * fix spacing
1 parent 3305752 commit 67276ab

2 files changed

Lines changed: 26 additions & 16 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',
122+
'#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R\s*\);\R\s*\})#s',
123123
static function (array $match) use ($prefix): string {
124124
$body = str_replace($prefix . '\\', '', $match[2]);
125125
$body = Strings::replace($body, '#^\s*namespace ' . preg_quote($prefix, '#') . ';\R\R?#m', '');

‎tests/Scoper/ScoperPatchersTest.php‎

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

55
namespace Rector\Tests\Scoper;
66

7-
use Webmozart\Assert\Assert;
87
use Closure;
98
use PHPUnit\Framework\TestCase;
109
use Symfony\Component\Finder\Finder;
@@ -30,28 +29,39 @@ public function getRuleDefinition(): RuleDefinition
3029
{
3130
$metadata = 'RectorPrefix202607\Webmozart\Assert\Assert';
3231
33-
new ConfiguredCodeSample(
34-
<<<'CODE_SAMPLE'
32+
return new RuleDefinition(
33+
'Demo',
34+
[
35+
new ConfiguredCodeSample(
36+
<<<'CODE_SAMPLE'
3537
<?php
3638
3739
namespace RectorPrefix202607;
3840
39-
use RectorPrefix202607\Webmozart\Assert\Assert;
41+
class SomeClass
42+
{
43+
public function run()
44+
{
45+
}
46+
}
4047
CODE_SAMPLE
41-
,
42-
<<<'CODE_SAMPLE'
48+
,
49+
<<<'CODE_SAMPLE'
4350
<?php
4451
52+
use RectorPrefix202607\Webmozart\Assert\Assert;
53+
4554
\RectorPrefix202607\Webmozart\Assert\Assert::allString($items);
4655
CODE_SAMPLE
47-
,
48-
[]
49-
);
50-
51-
new CodeSample(
52-
'RectorPrefix202607\SomeVendor\ValueObject::class',
53-
'new RectorPrefix202607\SomeVendor\ValueObject()'
54-
);
56+
,
57+
[]
58+
),
59+
new CodeSample(
60+
'RectorPrefix202607\SomeVendor\ValueObject::class',
61+
'new RectorPrefix202607\SomeVendor\ValueObject()'
62+
),
63+
]
64+
);
5565
}
5666
5767
public function refactor(): void
@@ -71,7 +81,7 @@ public function refactor(): void
7181

7282
$this->assertStringContainsString('use Webmozart\Assert\Assert;', (string) $content);
7383
$this->assertStringContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', (string) $content);
74-
$this->assertStringContainsString(Assert::class . '::allString($items);', (string) $content);
84+
$this->assertStringContainsString('\Webmozart\Assert\Assert::allString($items);', (string) $content);
7585
$this->assertStringContainsString("'SomeVendor\ValueObject::class'", (string) $content);
7686
$this->assertStringContainsString("'new SomeVendor\ValueObject()'", (string) $content);
7787
$this->assertStringContainsString('$metadata = \'Webmozart\Assert\Assert\';', (string) $content);

0 commit comments

Comments
 (0)