Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'#(public function getRuleDefinition\(\): RuleDefinition\s+\{\R)(.*?)(\R\s*\);\R\s*\})#s',
static function (array $match) use ($prefix): string {
$body = str_replace($prefix . '\\', '', $match[2]);
$body = Strings::replace($body, '#^\s*namespace ' . preg_quote($prefix, '#') . ';\R\R?#m', '');
Expand Down
40 changes: 25 additions & 15 deletions tests/Scoper/ScoperPatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\Tests\Scoper;

use Webmozart\Assert\Assert;
use Closure;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Finder;
Expand All @@ -30,28 +29,39 @@ public function getRuleDefinition(): RuleDefinition
{
$metadata = 'RectorPrefix202607\Webmozart\Assert\Assert';

new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
return new RuleDefinition(
'Demo',
[
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
<?php

namespace RectorPrefix202607;

use RectorPrefix202607\Webmozart\Assert\Assert;
class SomeClass
{
public function run()
{
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
,
<<<'CODE_SAMPLE'
<?php

use RectorPrefix202607\Webmozart\Assert\Assert;

\RectorPrefix202607\Webmozart\Assert\Assert::allString($items);
CODE_SAMPLE
,
[]
);

new CodeSample(
'RectorPrefix202607\SomeVendor\ValueObject::class',
'new RectorPrefix202607\SomeVendor\ValueObject()'
);
,
[]
),
new CodeSample(
'RectorPrefix202607\SomeVendor\ValueObject::class',
'new RectorPrefix202607\SomeVendor\ValueObject()'
),
]
);
}

public function refactor(): void
Expand All @@ -71,7 +81,7 @@ public function refactor(): void

$this->assertStringContainsString('use Webmozart\Assert\Assert;', (string) $content);
$this->assertStringContainsString('use RectorPrefix202607\Webmozart\Assert\Assert;', (string) $content);
$this->assertStringContainsString(Assert::class . '::allString($items);', (string) $content);
$this->assertStringContainsString('\Webmozart\Assert\Assert::allString($items);', (string) $content);
$this->assertStringContainsString("'SomeVendor\ValueObject::class'", (string) $content);
$this->assertStringContainsString("'new SomeVendor\ValueObject()'", (string) $content);
$this->assertStringContainsString('$metadata = \'Webmozart\Assert\Assert\';', (string) $content);
Expand Down
Loading