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*\]?\);\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],
Expand Down
26 changes: 5 additions & 21 deletions tests/Scoper/ScoperPatchersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Tests\Scoper;

use Webmozart\Assert\Assert;
use Closure;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Finder\Finder;
Expand All @@ -27,13 +28,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'
<?php

namespace RectorPrefix202607;
Expand All @@ -46,8 +41,7 @@ public function run()
}
\class_alias('SomeClass', 'SomeClass', \false);
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
, <<<'CODE_SAMPLE'
<?php

namespace RectorPrefix202607;
Expand All @@ -63,15 +57,7 @@ public function run()
}
\class_alias('SomeClass', 'SomeClass', \false);
CODE_SAMPLE
,
[]
),
new CodeSample(
'RectorPrefix202607\SomeVendor\ValueObject::class',
'new RectorPrefix202607\SomeVendor\ValueObject()'
),
]
);
, [AssertClassName::WEBMOZART])]);
}

public function refactor(): void
Expand Down Expand Up @@ -110,9 +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("'SomeVendor\ValueObject::class'", (string) $content);
$this->assertStringContainsString('$metadata = \'Webmozart\Assert\Assert\';', (string) $content);
$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);
Expand Down
Loading